Skip to content

Commit a484cf2

Browse files
committed
fix crashes and hangs in arc()
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
1 parent 288f4bf commit a484cf2

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
1414
* `rgba(r,g,b)` with no alpha should parse as opaque, not transparent. ([#2029](https://github.com/Automattic/node-canvas/issues/2029))
1515
* Typo in `PngConfig.filters` types. ([#2072](https://github.com/Automattic/node-canvas/issues/2072))
1616
* `createPattern()` always used "repeat" mode; now supports "repeat-x" and "repeat-y". ([#2066](https://github.com/Automattic/node-canvas/issues/2066))
17+
* Crashes and hangs when using non-finite values in `context.arc()`. ([#2055](https://github.com/Automattic/node-canvas/issues/2055))
1718

1819
2.9.3
1920
==================

src/CanvasRenderingContext2d.cc

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,35 +2936,34 @@ NAN_METHOD(Context2d::Rect) {
29362936
}
29372937

29382938
/*
2939-
* Adds an arc at x, y with the given radis and start/end angles.
2939+
* Adds an arc at x, y with the given radii and start/end angles.
29402940
*/
29412941

29422942
NAN_METHOD(Context2d::Arc) {
2943-
if (!info[0]->IsNumber()
2944-
|| !info[1]->IsNumber()
2945-
|| !info[2]->IsNumber()
2946-
|| !info[3]->IsNumber()
2947-
|| !info[4]->IsNumber()) return;
2943+
double args[5];
2944+
if(!checkArgs(info, args, 5))
2945+
return;
29482946

2949-
bool anticlockwise = Nan::To<bool>(info[5]).FromMaybe(false);
2947+
auto x = args[0];
2948+
auto y = args[1];
2949+
auto radius = args[2];
2950+
auto startAngle = args[3];
2951+
auto endAngle = args[4];
2952+
2953+
if (radius < 0) {
2954+
Nan::ThrowRangeError("The radius provided is negative.");
2955+
return;
2956+
}
2957+
2958+
bool counterclockwise = Nan::To<bool>(info[5]).FromMaybe(false);
29502959

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

2954-
if (anticlockwise && M_PI * 2 != Nan::To<double>(info[4]).FromMaybe(0)) {
2955-
cairo_arc_negative(ctx
2956-
, Nan::To<double>(info[0]).FromMaybe(0)
2957-
, Nan::To<double>(info[1]).FromMaybe(0)
2958-
, Nan::To<double>(info[2]).FromMaybe(0)
2959-
, Nan::To<double>(info[3]).FromMaybe(0)
2960-
, Nan::To<double>(info[4]).FromMaybe(0));
2963+
if (counterclockwise && M_PI * 2 != endAngle) {
2964+
cairo_arc_negative(ctx, x, y, radius, startAngle, endAngle);
29612965
} else {
2962-
cairo_arc(ctx
2963-
, Nan::To<double>(info[0]).FromMaybe(0)
2964-
, Nan::To<double>(info[1]).FromMaybe(0)
2965-
, Nan::To<double>(info[2]).FromMaybe(0)
2966-
, Nan::To<double>(info[3]).FromMaybe(0)
2967-
, Nan::To<double>(info[4]).FromMaybe(0));
2966+
cairo_arc(ctx, x, y, radius, startAngle, endAngle);
29682967
}
29692968
}
29702969

0 commit comments

Comments
 (0)