Skip to content

fix(docs-tools): make the Kotlin class regex linear - #74

Merged
rennf93 merged 1 commit into
masterfrom
fix/code-scanning-alerts
Oct 21, 2026
Merged

rennf93 merged 1 commit into
masterfrom
fix/code-scanning-alerts

Conversation

@rennf93

@rennf93 rennf93 commented Oct 21, 2026

Copy link
Copy Markdown
Member

Closes the CodeQL py/redos alert #1 on docs/tools/w8c_extract.py:351.

In KT_CLASS_RE the annotation token @\w+[^ ]* can split a run of word characters between \w+ and [^ ]* in many ways, so a line that starts with annotations and is not a class declaration backtracks exponentially. @\w\S* matches the same tokens with one parse: \w+[^ ]* and \w[^ ]* accept the same strings, and \S* no longer competes with the following \s+.

Checked:

  • Old and new pattern on every .kt line of this repository: 89789 lines, 691 class matches, 0 differences in the captured name.
  • On "@" + "a0 @" * 22 the old pattern takes 3.710 s (0.206 s at 18), the new one 0.000008 s.
  • w8c_extract.py is a docs tool; the Gradle build does not use it, so I did not run ./gradlew build for this change.

@rennf93 rennf93 added the no-issue Chore or dependency PR that does not need an issue label Oct 21, 2026
@github-actions github-actions Bot added the documentation Docs, README, CHANGELOG, license files label Oct 21, 2026
@rennf93
rennf93 merged commit db4e59e into master Oct 21, 2026
8 checks passed
@rennf93
rennf93 deleted the fix/code-scanning-alerts branch October 21, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Docs, README, CHANGELOG, license files no-issue Chore or dependency PR that does not need an issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant