Skip to content

Conversation

@muellerj2
Copy link
Contributor

Resolves #5944.

This limits the number of state transitions by a complexity limit that grows linearly in the length of the input string. Additionally, this also takes into account the length of string comparisons in _N_str and _N_back nodes (though divided by 64, as comparing one character is much cheaper than a single state transition).

I implemented a complexity limit of 300000 + 256 * input string length. I think that should be enough for reasonable uses (and it's likely this limit will become more generous in practice when #5971 is addressed): Matching the regex a* currently performs about 3 state transitions per matched character, so 85 such loops can be tried before a complexity exception is thrown.

The limit might be larger than what can fit into _Iter_diff_t<_It> (or ptrdiff_t). For this reason, two counter variables are used to implement the limit.

Drive-by change: I somehow missed that _Matcher3::_Pop_frame() is no longer in use, so this PR removes this function as well.

@muellerj2 muellerj2 requested a review from a team as a code owner January 10, 2026 16:21
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews Jan 10, 2026
@muellerj2 muellerj2 changed the title s<regex>: Revise complexity limit <regex>: Revise complexity limit Jan 10, 2026
@StephanTLavavej StephanTLavavej added enhancement Something can be improved regex meow is a substring of homeowner labels Jan 10, 2026
@StephanTLavavej StephanTLavavej self-assigned this Jan 10, 2026
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

Status: Initial Review

Development

Successfully merging this pull request may close these issues.

<regex>: Revising the stack and complexity limits

2 participants