Deeply nested <div> causes hang in parser (realistic example)#60816
Merged
webkit-commit-queue merged 1 commit intoWebKit:mainfrom Mar 18, 2026
Merged
Conversation
Collaborator
|
EWS run on previous version of this PR (hash 8b0bf99) Details
|
8b0bf99 to
c8d3c22
Compare
Collaborator
|
EWS run on current version of this PR (hash c8d3c22) Details
|
rreno
approved these changes
Mar 17, 2026
Member
rreno
left a comment
There was a problem hiding this comment.
Test case hangs for me on shipping Safari, nice.
whsieh
approved these changes
Mar 17, 2026
https://bugs.webkit.org/show_bug.cgi?id=309208 rdar://171763407 Reviewed by Wenson Hsieh and Ryan Reno. This PR fixes an infinite loop in the HTML parser that occurs when parser hits the tree depth limit. The HTML parser limits the DOM tree depth at 512. When this limit is reached, HTMLConstructionSite's attachLater pops the top element from the open elements stack before pushing the new element, keeping the depth at 512. The problem is that this pop-and-push happens blindly — it can pop table-internal elements such as table, tbody, tr, td, th, that the parser's insertion mode state machine depends on. This creates an inconsistency between the insertion mode and the actual stack contents and causes an infinite loop. With the test case specifically, td fails to get inserted into the stack of open elements, resulting in the parser state to be InsertionMode::InCell without having td/th in the stack of open elements. When `</table>` arrives in this state, HTMLTreeBuilder's closeTheCell fails silently and falls into an infinite loop. To fix this problem, this PR adds a new boolean state in HTMLConstructionSite, which indicates that we've reached the maximum tree depth, and checks this state in HTMLTreeBuilder. When the flag is set, we call resetInsertionModeAppropriately to correct the insertion mode to be consistent with the stack of open elements. Analysis done with Claude AI. Test: fast/parser/html-parser-depth-limit-hang.html * LayoutTests/fast/parser/html-parser-depth-limit-hang-expected.txt: Added. * LayoutTests/fast/parser/html-parser-depth-limit-hang.html: Added. * Source/WebCore/html/parser/HTMLConstructionSite.cpp: (WebCore::HTMLConstructionSite::attachLater): Set m_hasReachedMaxDOMTreeDepth to true when we've\ reached the maximum tree depth of 512. * Source/WebCore/html/parser/HTMLConstructionSite.h: (WebCore::HTMLConstructionSite::hasReachedMaxDOMTreeDepth const): Added. * Source/WebCore/html/parser/HTMLTreeBuilder.cpp: (WebCore::HTMLTreeBuilder::processStartTagForInBody): (WebCore::HTMLTreeBuilder::processStartTagForInTable): (WebCore::HTMLTreeBuilder::processStartTag): Ditto. (WebCore::HTMLTreeBuilder::processEndTagForInTableBody): (WebCore::HTMLTreeBuilder::processEndTagForInRow): (WebCore::HTMLTreeBuilder::processTrEndTagForInRow): (WebCore::HTMLTreeBuilder::processTableEndTagForInTable): Canonical link: https://commits.webkit.org/309454@main
c8d3c22 to
aff0077
Compare
Collaborator
|
Committed 309454@main (aff0077): https://commits.webkit.org/309454@main Reviewed commits have been landed. Closing PR #60816 and removing active labels. |
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.
🛠 ios-apple
aff0077
c8d3c22
🛠 win🧪 win-tests