Don't raise IndexError on an unbalanced transform expression - #508
Merged
deeplook merged 1 commit intoAug 17, 2026
Merged
Conversation
convertTransform collected the positions of all parentheses and iterated them two at a time as open/close pairs. A transform with an unmatched parenthesis (e.g. 'scale(2') left an odd number of positions, so brackets[i + 1] indexed past the list. Stop before a final unmatched bracket; such a transform is then reported as unparsable and ignored, like other invalid transforms.
Owner
|
Thanks for the fix and tests! |
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 transform attribute with an unmatched parenthesis crashes the converter:
convertTransformcollects the indices of all(/)characters and walks them two at a time as open/close pairs viarange(0, len(brackets), 2), readingbrackets[i + 1]. An unmatched parenthesis leaves an odd number of positions, so the last iteration indexes past the list. I step tolen(brackets) - 1so a final unmatched bracket is skipped; the transform is then reported as unparsable and ignored, matching how other invalid transforms are handled. Valid transforms are unaffected.Extended the existing
TestTransformAttrConvertermapping with unbalanced cases; it raises IndexError onmainand passes with the change. Found it by fuzzingsvg2rlgwith mutated SVG.