`<regex>`: Limit recursion in the parser by muellerj2 · Pull Request #5588 · microsoft/STL · GitHub
Skip to content

<regex>: Limit recursion in the parser#5588

Merged
StephanTLavavej merged 1 commit into
microsoft:mainfrom
muellerj2:regex-limit-recursion-in-parser
Jul 15, 2025
Merged

<regex>: Limit recursion in the parser#5588
StephanTLavavej merged 1 commit into
microsoft:mainfrom
muellerj2:regex-limit-recursion-in-parser

Conversation

@muellerj2

Copy link
Copy Markdown

#4451 limited recursion for capture groups in the parser. However, unlimited recursion in the parser is still possible for regexes that use non-capturing groups or lookahead assertions. This PR similarly limits the recursion for such constructs by using the parser's pre-existing internal recursion counter, _Disj_count.

This supersedes the capture group limit introduced by #4451 as a way to prevent stack overflows. But I'm leaving it in because regexes using more than 1000 capture groups strike me as bogus anyway. (I think the error code error_space would be more appropriate in this case now, since the limit is no longer about preventing recursion, but it's probably not worth introducing a minor behavior difference just for this reason. One could even argue that error_space is more appropriate for the new stack limit introduced by this PR, too, because error_space is about regex construction, while error_stack is about regex matching.)

I also fix a mistake in _Matcher2::_Skip()'s recursion limitation: In #5576, I accidentally missed to pass the recursion counter as an argument to one of the recursive calls.

@muellerj2 muellerj2 requested a review from a team as a code owner June 14, 2025 15:05
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews Jun 14, 2025
@StephanTLavavej StephanTLavavej self-assigned this Jun 14, 2025
@StephanTLavavej StephanTLavavej added enhancement Something can be improved regex meow is a substring of homeowner labels Jun 14, 2025
@StephanTLavavej StephanTLavavej removed their assignment Jun 14, 2025
@StephanTLavavej StephanTLavavej moved this from Initial Review to Ready To Merge in STL Code Reviews Jun 14, 2025
@StephanTLavavej StephanTLavavej moved this from Ready To Merge to Merging in STL Code Reviews Jul 14, 2025
@StephanTLavavej

Copy link
Copy Markdown
Member

@StephanTLavavej StephanTLavavej merged commit a1f193d into microsoft:main Jul 15, 2025
39 checks passed
@github-project-automation github-project-automation Bot moved this from Merging to Done in STL Code Reviews Jul 15, 2025
@StephanTLavavej

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Something can be improved regex meow is a substring of homeowner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants