Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(regex): limit regex manager iterations to 10k to avoid OoM #22084

Merged
merged 2 commits into from May 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/modules/manager/regex/utils.spec.ts
@@ -0,0 +1,14 @@
import { regEx } from '../../../util/regex';
import * as utils from './utils';

describe('modules/manager/regex/utils', () => {
it('does not crash for lazy regex', () => {
const lazyMatch = regEx('(?<currentDigest>.*?)', 'g');
expect(
utils.regexMatchAll(
lazyMatch,
'1f699d2bfc99bbbe4c1ed5bb8fc21e6911d69c6e\n'
)
).toBeArray();
});
});
5 changes: 4 additions & 1 deletion lib/modules/manager/regex/utils.ts
Expand Up @@ -85,12 +85,15 @@ export function regexMatchAll(
): RegExpMatchArray[] {
const matches: RegExpMatchArray[] = [];
let matchResult: RegExpMatchArray | null;
let iterations = 0;
const maxIterations = 10000;
do {
matchResult = regex.exec(content);
if (matchResult) {
matches.push(matchResult);
}
} while (matchResult);
iterations += 1;
} while (matchResult && iterations < maxIterations);
return matches;
}

Expand Down