fix: O(1) fast-reject for unclosed link syntax to prevent quadratic-time DoS. - #4071
Closed
rishaankgupta wants to merge 2 commits into
Closed
fix: O(1) fast-reject for unclosed link syntax to prevent quadratic-time DoS.#4071rishaankgupta wants to merge 2 commits into
rishaankgupta wants to merge 2 commits into
Conversation
|
@rishaankgupta is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
Member
|
Is this the same fix as #4070? |
Author
|
Yeah, same root cause and approach same fix idea. theirs looks more refined at this |
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.
Fixes the algorithmic complexity issue described in GHSA-66g2-49g4-pwrq.
The inline tokenizer's link-matching attempt was repeated once per
unmatched '[' across the loop, each call costing time proportional to
the remaining string length when no closing ')' exists ahead --
aggregate O(n^2) for long runs of unclosed "[x](" sequences.
This adds a one-time O(n) precomputation of the last ')' position
before the loop, then an O(1) check per iteration to skip the link
attempt entirely when it's structurally impossible to match.
Verified against the full spec suite (1,783 tests, including all
existing quadratic/redos regression tests) -- all pass. Added a new
regression test (quadratic_link_unclosed_repeated.cjs) covering this
specific case.
Benchmark: 250KB adversarial payload, 26.66s -> 136.86ms.