Skip to content

Reject negative radii in arcTo() and ellipse() - #2635

Open
1AbdullahButt wants to merge 1 commit into
Automattic:masterfrom
1AbdullahButt:fix/2626-negative-radius
Open

1AbdullahButt wants to merge 1 commit into
Automattic:masterfrom
1AbdullahButt:fix/2626-negative-radius

Conversation

@1AbdullahButt

Copy link
Copy Markdown

Thanks for contributing!

  • Have you updated CHANGELOG.md?

Fixes #2626

arc() throws a RangeError for a negative radius, but arcTo() and ellipse() didn't check:

  • arcTo() handled degenerate points and a zero radius first, so ctx.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 a RangeError, the same way arc() does. The vendored WPT cases (2d.path.arcTo.negative, 2d.path.ellipse.basics) expect INDEX_SIZE_ERR. I kept the RangeError that arc() already uses, so the three methods behave the same.

Tests

  • Two tests in test/canvas.test.js. They check that arcTo() throws for a negative radius (also with points that would draw a straight line) and that ellipse() throws for a negative radiusX or radiusY. They also check that the path isn't changed, and that zero and NaN radii still don't throw. Both fail before this change and pass after it.
  • zig build plus npm test on Linux (Node 22, Docker): 307 passing, 6 pending.
  • npm run lint passes.

This change was written with Claude Code (an AI coding assistant).

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

arcTo and ellipse accept negative radii

1 participant