Repository navigation
Refuse a page that nests too deeply to render instead of overflowing the stack - #19
Open
sharmis-tp wants to merge 1 commit into
Open
sharmis-tp wants to merge 1 commit into
sharmis-tp wants to merge 1 commit into
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
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.
A page with about 2,000 nested elements, only about 10 KB of HTML, makes
web/fetchabort the whole process.htmdrecurses once per level of nesting and overflows the 2 MiB stack of the thread that renders. A stack overflow is not a panic, so nothing can catch it. It happens with and withoutraw, so any page a model fetches can trigger it. On master (b2c5749), a release build crashes at a depth of 2,000 and a debug build at 1,000.To reproduce:
served as
text/htmland fetched withweb/fetch.The fix:
html_tree.rsparses the HTML with html5ever in 4 KB chunks. Between chunks it stops once more than 512 elements are open, and it checks the finished tree for a depth over 256. So a deep page is refused while it is read, not after it. The parser's own time also grows with the square of the depth.htmdroom on the stack even in a debug build.extract_htmlparses with it first, and the whole-page render parses the absolutized HTML through it again, so both the article path andraware covered.FetchError::TooDeep: "the HTML of {url} nests elements more than 256 levels deep, which is the limit; try a different URL". The model gets it like any other soft failure and can try another URL.Tests: the
/deeproute serves 100,000 nested<div>s, anda_page_nested_too_deeply_is_refused_with_and_without_rawchecks that both modes return the error instead of crashing.disposition_tablealso listsTooDeepas soft. fmt, clippy, nextest (184 passed), doc and the release build all pass locally.If #18 merges first, the deep test's
callneeds a trailing, None, and I'll rebase.