Skip to content

Commit

Permalink
fix crashes and hangs in arc()
Browse files Browse the repository at this point in the history
The WPT tests for this now pass. See issue for test content; I think it makes more sense to land the WPT tests than to copy individual ones into the node-canvas tests.

Fixes #2055
  • Loading branch information
zbjornson committed Jul 27, 2022
1 parent c6a1546 commit 305f5ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
* `rgba(r,g,b)` with no alpha should parse as opaque, not transparent. ([#2029](https://github.com/Automattic/node-canvas/issues/2029))
* Typo in `PngConfig.filters` types. ([#2072](https://github.com/Automattic/node-canvas/issues/2072))
* `createPattern()` always used "repeat" mode; now supports "repeat-x" and "repeat-y". ([#2066](https://github.com/Automattic/node-canvas/issues/2066))
* Crashes and hangs when using non-finite values in `context.arc()`. ([#2055](https://github.com/Automattic/node-canvas/issues/2055))

2.9.3
==================
Expand Down
39 changes: 19 additions & 20 deletions src/CanvasRenderingContext2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2936,35 +2936,34 @@ NAN_METHOD(Context2d::Rect) {
}

/*
* Adds an arc at x, y with the given radis and start/end angles.
* Adds an arc at x, y with the given radii and start/end angles.
*/

NAN_METHOD(Context2d::Arc) {
if (!info[0]->IsNumber()
|| !info[1]->IsNumber()
|| !info[2]->IsNumber()
|| !info[3]->IsNumber()
|| !info[4]->IsNumber()) return;
double args[5];
if(!checkArgs(info, args, 5))
return;

bool anticlockwise = Nan::To<bool>(info[5]).FromMaybe(false);
auto x = args[0];
auto y = args[1];
auto radius = args[2];
auto startAngle = args[3];
auto endAngle = args[4];

if (radius < 0) {
Nan::ThrowRangeError("The radius provided is negative.");
return;
}

bool counterclockwise = Nan::To<bool>(info[5]).FromMaybe(false);

Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
cairo_t *ctx = context->context();

if (anticlockwise && M_PI * 2 != Nan::To<double>(info[4]).FromMaybe(0)) {
cairo_arc_negative(ctx
, Nan::To<double>(info[0]).FromMaybe(0)
, Nan::To<double>(info[1]).FromMaybe(0)
, Nan::To<double>(info[2]).FromMaybe(0)
, Nan::To<double>(info[3]).FromMaybe(0)
, Nan::To<double>(info[4]).FromMaybe(0));
if (counterclockwise && M_PI * 2 != endAngle) {
cairo_arc_negative(ctx, x, y, radius, startAngle, endAngle);
} else {
cairo_arc(ctx
, Nan::To<double>(info[0]).FromMaybe(0)
, Nan::To<double>(info[1]).FromMaybe(0)
, Nan::To<double>(info[2]).FromMaybe(0)
, Nan::To<double>(info[3]).FromMaybe(0)
, Nan::To<double>(info[4]).FromMaybe(0));
cairo_arc(ctx, x, y, radius, startAngle, endAngle);
}
}

Expand Down

0 comments on commit 305f5ab

Please sign in to comment.