Repository navigation
Reject negative radii in arcTo() and ellipse() - #2635
Open
1AbdullahButt wants to merge 1 commit into
Open
1AbdullahButt wants to merge 1 commit into
1AbdullahButt wants to merge 1 commit into
Conversation
arc() already throws a RangeError for a negative radius, but arcTo() drew with it (or turned it into a straight line for degenerate points) and ellipse() passed negative radii to Cairo. Check the radii first, after the non-finite check, the same way arc() does. Fixes Automattic#2626 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Thanks for contributing!
Fixes #2626
arc()throws aRangeErrorfor a negative radius, butarcTo()andellipse()didn't check:arcTo()handled degenerate points and a zero radius first, soctx.arcTo(0, 0, 0, 0, -1)silently drew a line. Otherwise it went on to draw with the negative radius.ellipse()only returned early for a zero radius and passed negative radii to Cairo.Both now check the radius right after the existing non-finite check (
checkArgs) and before touching the path. They throw aRangeError, the same wayarc()does. The vendored WPT cases (2d.path.arcTo.negative,2d.path.ellipse.basics) expectINDEX_SIZE_ERR. I kept theRangeErrorthatarc()already uses, so the three methods behave the same.Tests
test/canvas.test.js. They check thatarcTo()throws for a negative radius (also with points that would draw a straight line) and thatellipse()throws for a negativeradiusXorradiusY. They also check that the path isn't changed, and that zero andNaNradii still don't throw. Both fail before this change and pass after it.zig buildplusnpm teston Linux (Node 22, Docker): 307 passing, 6 pending.npm run lintpasses.This change was written with Claude Code (an AI coding assistant).
🤖 Generated with Claude Code