Don't crash serializing an unknown rule with an unmatched closing brace - #80
Open
eeshsaxena wants to merge 1 commit into
Open
Don't crash serializing an unknown rule with an unmatched closing brace#80eeshsaxena wants to merge 1 commit into
eeshsaxena wants to merge 1 commit into
Conversation
do_CSSUnknownRule walks the rule's token sequence keeping a stack of open
blocks, popping on each '}'. A '}' with no matching '{' (from a malformed
at-rule) left the stack empty, so stacks.pop() raised IndexError while
computing cssText. Only pop when the stack is non-empty; a stray '}' is then
emitted as a plain token.
Author
|
Hi! Gentle nudge on this one whenever you have some bandwidth. It's a small, self-contained fix ( |
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.
Parsing then serializing certain malformed at-rules raises
IndexErrorfrom the serializer:do_CSSUnknownRulewalks the rule's token sequence keeping a stack of open blocks and pops it on every}. A}with no matching{(which the tokenizer can leave in the sequence for a malformed at-rule) makes it pop from an empty list. I guard the pop withand stacks; a stray}then falls through and is emitted as a plain token. Well-formed unknown rules (including nested blocks) serialize exactly as before.Added a test to
TestCSSUnknownRule; it raises IndexError onmainand passes with the change, and the unknown-rule and serialize suites still pass. Found it by fuzzingparseString+cssText.