Skip to content

🐛 fix(dom): keep text order after the depth cap lifts - #2545

Merged
gaborbernat merged 5 commits into
tox-dev:mainfrom
gaborbernat:fix/fuzz-encoding-text
Nov 21, 2026
Merged

gaborbernat merged 5 commits into
tox-dev:mainfrom
gaborbernat:fix/fuzz-encoding-text

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

The scheduled fuzzer's encoding target compares a byte parse against a parse of the decoded text and against html5lib. Three of its findings on main come from two causes, one in the parser and one in the oracle.

Parser: text order after the depth cap lifts. The DOM stops at 512 levels. An append the cap refuses goes after its parent instead, and the docs promise that text keeps its source order. The adoption agency can then move that parent back under the cap: eight blocks under an <a> run its outer loop to its end, and the last one lifts the paragraph inside them. The next append went into the paragraph, ahead of the text the cap had already placed after it:

parse("<a>" + "<x>" * 500 + "<div>" * 8 + "<p>y<a>x").text  # 'xy' before, 'yx' now

A parent the cap refused now keeps refusing, so later content lands after the earlier run. The check costs nothing until a parse first gets near the cap.

Oracle: html5lib's in-body "any other end tag" ignores namespaces. WHATWG matches only an HTML element of the token's name and stops at the first special element. html5lib compares bare names, so in <math><mi><x></mi> it pops back to <math>, where turbohtml correctly stops at the special MathML mi. A NUL after that point is foreign content to html5lib (U+FFFD) and in-body content to turbohtml (dropped). The reference wrapper now patches the handler, as it already does for the adoption agency and several other html5lib gaps.

An append the 512-level cap refuses goes after its parent instead. When the
adoption agency later moves that parent back under the cap, the next append
went into it, ahead of the nodes already placed after it. A parent the cap
refused now keeps refusing.
@gaborbernat gaborbernat added the bug Something isn't working label Nov 21, 2026
@codspeed

codspeed Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 580 untouched benchmarks
⏩ 91 skipped benchmarks1


Comparing gaborbernat:fix/fuzz-encoding-text (fbc25da) with main (a58211e)

Open in CodSpeed

Footnotes

  1. 91 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Copying an option into a selectedcontent removes the selectedcontent's
children, which can detach an element the cap refused while it is still
open. The next append into it followed the refused element's parent, now
NULL, and crashed.
@gaborbernat
gaborbernat merged commit 500ee53 into tox-dev:main Nov 21, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant