Skip to content

Cap word count in normalizeLicenseWords#12

Merged
andrew merged 1 commit intomainfrom
fix/normalize-word-count-cap
May 2, 2026
Merged

Cap word count in normalizeLicenseWords#12
andrew merged 1 commit intomainfrom
fix/normalize-word-count-cap

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented May 2, 2026

The nested-loop matching in `normalizeLicenseWords` tries progressively shorter word spans from each position, giving O(n^2) behavior in the number of words. A ~3 KB string can pin a CPU core for minutes.

Adds a 256-word cap at the top of the function. No real SPDX expression comes close to this limit.

The nested-loop matching in normalizeLicenseWords is O(n^2) in the
number of words. A ~3 KB input string with many words can pin a CPU
core for minutes. Rejects inputs with more than 256 words, which is
far beyond any real SPDX expression.
@andrew andrew merged commit 72d07c7 into main May 2, 2026
2 checks passed
@andrew andrew deleted the fix/normalize-word-count-cap branch May 2, 2026 15:36
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