Skip to content

Conversation

muellerj2
Copy link
Contributor

#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
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@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
Member

Thanks for closing this potential avenue to stack overflows! 🛑 ❌ ⛔

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
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants