Skip to content

fix: replace quadratic regex with line-scoped search in check-published-numbers - #53

Merged
svghadi merged 2 commits into
mainfrom
fix/check-numbers-regex-linear
Nov 27, 2026
Merged

svghadi merged 2 commits into
mainfrom
fix/check-numbers-regex-linear

Conversation

@svghadi

@svghadi svghadi commented Nov 27, 2026

Copy link
Copy Markdown
Member

Summary

  • Replace two quadratic regex patterns in scripts/check-published-numbers.py with a linear alternative: locate the matching table row by plain string search first, then apply the regex only to that bounded line.
  • The patterns at lines 60 and 76 used [^|]* (unbounded) before a required | literal, which backtracks quadratically on crafted input.
  • No behavior change on well-formed README tables.

Thanks to Jiawei Guo for the careful analysis that surfaced this.

Test plan

  • python3 scripts/check-published-numbers.py passes against existing benchmark files
  • CI passes

🤖 Generated with Claude Code

svghadi and others added 2 commits November 27, 2026 13:04
…ed-numbers

The patterns at lines 60 and 76 used [^|]* (unbounded) followed by a
required | literal, causing quadratic backtracking on crafted README input.
Replace with a plain line lookup followed by a regex applied only to that
bounded line, making the scan linear. No behavior change on well-formed tables.

Thanks to Jiawei Guo for the careful analysis that surfaced this.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Restrict row lookup to lines starting with | (actual table rows) and
check the skill name against the first column only, preventing false
matches against prose mentions or unrelated table columns. Also move
splitlines() outside the per-skill loop.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@svghadi
svghadi merged commit 8173b9b into main Nov 27, 2026
2 checks passed
@svghadi
svghadi deleted the fix/check-numbers-regex-linear branch November 27, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant