Repository navigation
fix: drop redundant repetition from star-led repeated extglobs - #257
Open
arturhvcpn wants to merge 1 commit into
Open
arturhvcpn wants to merge 1 commit into
arturhvcpn wants to merge 1 commit into
Conversation
`+(*a)` and `*(*a)` compiled to `(?:[^/]*?a)+`, which backtracks exponentially on non-matching input (GHSA-fc5q-39xc-vjpf). A branch that starts with a `*` that cannot match `/` (no `/`, `**` or brackets) already absorbs any earlier repetitions, so `+(...)` can close like `@(...)` and `*(...)` like `?(...)` without changing what matches.
arturhvcpn
force-pushed
the
fix-redos-star-led-extglob
branch
from
November 17, 2026 20:30
953dcbd to
4e4892e
Compare
|
See #235 (comment). |
msalaheldincontractor-wsl
approved these changes
Nov 17, 2026
|
Reviewed from the diff; I did not run this branch. For reference, on master (9fab7bf, Node 22) each of
|
This was referenced Nov 17, 2026
This was referenced Nov 18, 2026
|
Both GitHub and VulnCheck have withdrawn this advisory, as it is not a security issue. If a tool is still reporting you're "vulnerable", then you need to contact the tool author about getting their source updated. |
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.
Summary
A repeated extglob whose branch starts with a plain
*(e.g.+(*a),*(*a)) compiles to a nested quantifier that backtracks exponentially on non-matching input. This is the issue reported in GHSA-fc5q-39xc-vjpf.Reproduction
Every extra character roughly doubles the time.
Root cause
analyzeRepeatedExtglobonly flags branches that are themselves*(…)sequences or nested extglobs. A branch such as*ais not flagged, so+(*a)is emitted as(?:[^/]*?a)+. Both the lazy[^/]*?and the outer+can consume the same run ofas, and the engine tries every way of splitting it before failing.Fix
A branch led by a plain
*that cannot match/already absorbs any earlier repetition:*a*amatches exactly what*amatches within a segment. So for such branches the repetition is redundant, and:+(…)closes like@(…)*(…)closes like?(…)+(*a)^(?:(?=.)(?:[^/]*?a)+)$^(?:(?=.)(?:[^/]*?a))$*(*a)^(?:(?=.)(?:[^/]*?a)*)$^(?:(?=.)(?:[^/]*?a)?)$+(*a|*b)^(?:(?=.)(?:[^/]*?a|[^/]*?b)+)$^(?:(?=.)(?:[^/]*?a|[^/]*?b))$The rewrite only applies when every branch is star-led and contains no
/,**or brackets (a bracket such as[[:punct:]]could match/, and then the leading star could not absorb the previous repetition).+(*/a)keeps its+. SettingmaxExtglobRecursion: falsekeeps the old output.After the change,
isMatch('a'.repeat(5000) + '!', '+(*a)')returns in 0ms.Validation
windows,posix,dot,bash,capture,nocase), 0 divergences.2000 passing), plusnpm run lint.test/options.maxExtglobRecursion.jsassert the generated source, match behaviour, the/case and themaxExtglobRecursion: falseopt-out.Known limitations
+(*a|b)are still exponential. There is no equivalent rewrite for them (dropping the+would change what matches), so they are left as they are.+(?*a)is currently compiled as a literal because of the leading?bug addressed in fix: treat a leading?in an extglob body as a wildcard #194. If fix: treat a leading?in an extglob body as a wildcard #194 is merged,+(?*a)would compile to a repeated[^/][^/]*?agroup, which this change does not cover.Refs GHSA-fc5q-39xc-vjpf