<regex>: Revise complexity limit
#6005
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_strand_N_backnodes (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 regexa*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>(orptrdiff_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.