Repository navigation
🐛 fix(rewrite): stop after a failed body replay - #2540
Merged
Merged
Conversation
When the rewriter could not allocate the tree it replays to find the body, it set MemoryError but still passed the current token to its handler. The handler then ran with the exception pending, and the next Python call raised SystemError instead of MemoryError. The token loop now stops as soon as that allocation fails.
Merging this PR will not alter performance
Comparing Footnotes
|
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.
rewrite()raisedSystemErrorinstead ofMemoryErrorwhen an allocation failed at one particular point.After the first edit, the rewriter replays the input into a tree to find where the body starts (
rw_start_following()). If allocating that tree failed, it setMemoryErrorand returned, but the token loop inturbohtml_rewrite()still handed the current token to its handler. A Python handler then ran with the exception already set, so its next call failed withSystemError: ... returned a result with an exception set.A minimal trigger is a document with an edit before a comment and a comment handler:
When the tree allocation fails, the comment handler's
set_textcall raisedSystemError. The loop now stops as soon asrw_start_following()reports the failure, sorewrite()raisesMemoryError.The new
rewrite-handler-after-editcase in the allocation-failure sweep (tests/_html/fuzz/test_self_test.py) fails every allocation of that call in turn. On main it yieldsSystemErrorfor one of them; with this change every one raisesMemoryError. The scheduled fuzz runs found this crash infuzz_dom_rewrite.