Repository navigation
Conversation
PARTICIPANT_DECLARATION_RE ended in an anchored `(?P<rest>.*)$`. On the
single lines the pattern is fed the anchor changed no result, since greedy
`.*` already runs to the end, but it gave the pattern a tail that can fail:
a newline in the name made `.*$` fail, and the engine then retried the tail
at every position it could backtrack `[^\s#]+` to -- quadratic in the name's
length (~0.4s at 8000 characters, against 0.08ms without the anchor).
Dropping the anchor makes the tail succeed on first try, so the name
repetition is never backtracked into. Behaviour is unchanged: the two
patterns return identical groupdicts across 108 declaration forms (quoted
and bare names, aliases, order/color/stereotype modifiers, indentation,
unterminated quotes and non-declarations).
No caller could reach the quadratic path, since participant_declarations
and rename.py both split the puml into lines first, so this hardens the
pattern rather than fixing a live defect. A timing test pins the linear
bound so the anchor is not reinstated.
Reported by CodeQL as py/polynomial-redos. Note for future triage that the
alert's suggested input ('participant !' with many '!!') is not in fact
slow -- it matches in linear time; the newline is what triggers the
backtracking.
rnva
marked this pull request as draft
October 8, 2026 18:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PARTICIPANT_DECLARATION_RE ended in an anchored
(?P<rest>.*)$. On the single lines the pattern is fed the anchor changed no result, since greedy.*already runs to the end, but it gave the pattern a tail that can fail: a newline in the name made.*$fail, and the engine then retried the tail at every position it could backtrack[^\s#]+to -- quadratic in the name's length (~0.4s at 8000 characters, against 0.08ms without the anchor).Dropping the anchor makes the tail succeed on first try, so the name repetition is never backtracked into. Behaviour is unchanged: the two patterns return identical groupdicts across 108 declaration forms (quoted and bare names, aliases, order/color/stereotype modifiers, indentation, unterminated quotes and non-declarations).
No caller could reach the quadratic path, since participant_declarations and rename.py both split the puml into lines first, so this hardens the pattern rather than fixing a live defect. A timing test pins the linear bound so the anchor is not reinstated.
Reported by CodeQL as py/polynomial-redos. Note for future triage that the alert's suggested input ('participant !' with many '!!') is not in fact slow -- it matches in linear time; the newline is what triggers the backtracking.