Repository navigation
Fix quadratic parsing of a line of *a_ - #1155
Merged
Martin1887 merged 3 commits intoSep 29, 2026
Merged
Conversation
Collaborator
|
Please add a test case to pulldown-cmark/dos-fuzzer/src/main.rs Line 179 in c574292 |
Contributor
Author
|
@notriddle Added |
A `_` that can close but not open and found no opener raised only UNDERSCORE_NOT_BOTH, while get_lowerbound for the next one takes the min of that and the still-zero mod-3 slot, so each such closer rescanned the whole stack. Raise both, as asterisks already do. A line of `*a_` went quadratic: 1.2 MB took 26.8 s, now 0.07 s. Fixes #1154.
The fuzzer parses with every option on, and under CJK-friendly emphasis a `*` right after `_` can also close, so `*a_` stays linear there. `*_ ` keeps the `*` opening-only and the `_` closing-only in both modes. With it, `--regressions` failed 9 of 10 runs on main and passed 10 of 10 with the fix.
HardMax71
force-pushed
the
underscore-lower-bound
branch
from
September 28, 2026 18:17
4d9b61d to
bb174f0
Compare
notriddle
reviewed
Sep 28, 2026
notriddle
approved these changes
Sep 28, 2026
Merged
Martin1887
added a commit
that referenced
this pull request
Oct 20, 2026
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 #1154.
set_lowerboundraised onlyUNDERSCORE_NOT_BOTHfor an underscore that can close but not open, whileget_lowerboundfor such a closer takes theminof that and the mod-3 slot, which stayed at 0. This raises both, the way asterisks already do. It's safe because a closer that can't open matches every opener that a two-way closer of the same length would match, so when its search fails, the two-way closer's search would fail over the same range too.A 1.2 MB line of
*a_took 26.8 s on main and takes 0.07 s here. The mirrored_a*was already linear.issue_1154inparse.rspushes three*openers, lets a closing-only_fail, and checks that both underscore bounds end up at 3. On main the closing-only bound stays at 0. The dos-fuzzer regressions now check*_too.*a_itself scores as linear there, because the fuzzer turns on CJK-friendly emphasis, where a*right after_can also close.*_keeps the*opening-only and the_closing-only in both modes, and--regressionsfailed 9 of 10 runs on main and passed 10 of 10 here.This should change no output. The full suite passes. I also compared main and this branch on 300,000 random short paragraphs of emphasis, strikethrough, super/subscript and highlight delimiters, with and without those extensions enabled, plus 400,000 underscore-heavy ones. The HTML came out byte-for-byte identical.