Repository navigation
Conversation
CodeQL js/polynomial-redos #3 remediation (reviewSchema.js:324-325). The strategy-5 regex retried its literal prefix at every index and rescanned the remaining suffix per candidate via the lazy body — quadratic on inputs repeating {"findings":[ without completion, on the shared worker event loop. Replacement: findFindingsPatternStart() — two monotonic indexOf passes with O(1) shape checks: (1) every literal "overall_correctness" occurrence is walked LEFT to collect valid ]-closes (ws* , ws* ], no suffix rescans); (2) every {"findings" occurrence gets the deterministic \s*:\s*\[ shape check and an existence test against the sorted close list. Linear total work. First-match-start semantics preserved (incl. empty-array [] closes — the lazy body may be zero-length; pinned by regression); the old indexOf(matchText) was provably redundant (an earlier occurrence of the full match text would itself be an earlier match, contradicting first-match selection) — noted in the scanner doc. Strategy 5's downstream flow (slice from match start, findMatchingBrace, JSON.parse, pattern_match identifier) unchanged. Regressions (review-schema-findings-pattern.test.js, 11 tests): - EQUIVALENCE: old regex + old strategy-5 flow reproduced verbatim (findMatchingBrace replicated); 7-member corpus (firing shapes, first candidate completing via later text, invalid-JSON tails, no-array candidates, later-partial candidates) asserts fire/no-fire agreement; tab-spread whitespace tolerance; first-candidate precedence - BOUNDEDNESS (<500ms): 30k repeated prefixes no completion (linear, falls through); 30k prefixes + one completion (shape completes, brace balance cannot close 30k opens — old flow identical terminal result); 1k-member single-candidate scale-up resolving pattern_match Full rules suite 342/342 (fence-scanner + pre-existing suites unchanged). Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
🤖 AI Code Review — ✅ Approved
Confidence: high · Findings: 1
AI judgment: APPROVE · Evidence: COMPLETE · Authority: advisory
Evidence complete · 2/2 changed files accounted for
Other findings (1)
- [low] Misleading invariant comment: validCloses are collected left-to-right, not right-to-left
🔮 Devil's Advocate (2 turns): 1 upheld
GitWire AI Review Gate (bundle-driven v2) · Structured schema · Scope-validated · Devil's Advocate · AI recommendation — maintainers and repository policy retain authority
| validCloses.sort((a, b) => a - b); // collected right-to-left | ||
|
|
||
| // Pass 2 — candidate heads in order; O(1) shape check plus an | ||
| // existence test against the sorted close list. |
There was a problem hiding this comment.
[LOW] Misleading invariant comment: validCloses are collected left-to-right, not right-to-left
In findFindingsPatternStart(), the comment // collected right-to-left on the sort line is factually wrong: the Pass 1 loop enumerates TAIL occurrences via indexOf in strictly ascending order, and each pushed close index i satisfies i < t with all closes strictly increasing (a later close cannot precede an earlier one, since the chars between a close and its tail must be whitespace/comma, which excludes an earlier close's ]). So validCloses is already sorted ascending and the sort is a defensive no-op — harmless, but the comment misstates the invariant in a security-sensitive bounded-scan algorithm and could mislead a future maintainer into reasoning incorrectly about ordering (e.g., 'fixing' the code to match the comment, or removing the sort while assuming the wrong order). Suggested fix: change the comment to something like // already ascending (indexOf enumerates tails left-to-right); sort is defensive or delete the sort with an accurate note. No functional impact.
|
Acknowledged and recorded as minor cleanup (per the interim review): |
Summary
Unit 3 of the authorized #425 remediation sequence (#5 → #1+#2 → #3 → #4). Remediation of CodeQL
js/polynomial-redos#3 (reviewSchema.js:324–325) under the corrected acceptance criterion: a monotonic scan that does not repeatedly rescan suffixes — not an anchored regex. Merge authority reserved; returned at exact head for clearance.The defect
Strategy 5's regex
/\{"findings"\s*:\s*\[[\s\S]*?\]\s*,\s*"overall_correctness"/retried its literal prefix at every index, and per candidate the lazy body rescanned the remaining suffix hunting for a completing]— quadratic on inputs that repeat{"findings":[without ever completing the pattern (each of the ~n/14 occurrences starts a fresh suffix expansion). Same shared-event-loop blast radius as #1/#2.The correction (per the corrected criterion)
New
findFindingsPatternStart()— two monotonicindexOfpasses, no suffix ever rescanned:"overall_correctness"once; for each occurrence walk left over the two whitespace runs to validate the] , "shape, collecting valid]positions. Each character is visited a constant number of times.{"findings"in order; per candidate, the deterministic\s*:\s*\[shape check (whitespace runs have exactly one viable split — the first non-whitespace character either is the required token or the candidate fails, no backtracking alternatives), then an existence test against the sorted close list.Total work linear in the input. First-match-start semantics preserved exactly, including the empty-array case (
[]— the lazy body may be zero-length, so a valid close exactly at the body start completes; caught and fixed during this unit's development as a strict->vs>=off-by-one my first scanner version had). The old code's extratrimmed.indexOf(matchText)was provably redundant and is noted in the scanner's documentation: an earlier occurrence of the full matched text would itself have been an earlier pattern match, contradicting first-match selection.Strategy 5's downstream flow — slice from the match start,
findMatchingBrace,JSON.parse,pattern_matchidentifier — is byte-unchanged.Regressions (
packages/rules/tests/review-schema-findings-pattern.test.js, 11 tests)Equivalence — the old regex and the old strategy-5 flow (match → slice → brace balance → parse, with
findMatchingBracereplicated verbatim) are reproduced in-tree; a 7-member corpus asserts fire/no-fire agreement: firing shapes (defeating strategies 1–4 by construction), first-candidate-completes-via-later-text (lazy-body reach), shape-completes-but-JSON-invalid,:-then-no-[candidates, later-partial candidates. Plus tab-spread whitespace tolerance and first-candidate precedence.Boundedness (all < 500 ms):
{"findings":[prefixes, no completion — linear, falls through.pattern_match.Verification
@gitwire/rulessuite 342/342 (fence-scanner and pre-existing suites unchanged).masterat 89d5e51) — both touchreviewSchema.jsbut disjoint regions (fence strategies vs strategy 5). Merge order fix(1/2): deterministic fenced-JSON extraction — linear worst case (CodeQL #1/#2) #466 → this PR is conflict-free; the reverse order needs a rebase.v2 note: replaces #467 — the original branch was accidentally stacked on the #465 and #466 commits. This branch is a single commit on master (89d5e51) carrying only the findings-pattern unit; the cherry-pick conflict (the shared insertion anchor with the fence unit) was resolved by keeping this branch free of fence-scanner changes. Rules suite 320/320 on this branch.