Skip to content

Commit a2e10e6

Browse files
mcfedrchearon
authored andcommitted
Throw surface errors in toBuffer
1 parent efcde93 commit a2e10e6

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ This release notably changes to using N-API. 🎉
3232
* Changed PNG consts to static properties of Canvas class
3333
### Added
3434
* Added string tags to support class detection
35+
* Throw Cairo errors in canvas.toBuffer()
3536
### Fixed
3637
* Fix a case of use-after-free. (#2229)
3738
* Fix usage of garbage value by filling the allocated memory entirely with zeros if it's not modified. (#2229)

src/Canvas.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,15 @@ Canvas::ToBuffer(const Napi::CallbackInfo& info) {
382382
closure = static_cast<SvgBackend*>(backend())->closure();
383383
}
384384

385-
cairo_surface_finish(surface());
385+
cairo_surface_t *surf = surface();
386+
cairo_surface_finish(surf);
387+
388+
cairo_status_t status = cairo_surface_status(surf);
389+
if (status != CAIRO_STATUS_SUCCESS) {
390+
Napi::Error::New(env, cairo_status_to_string(status)).ThrowAsJavaScriptException();
391+
return env.Undefined();
392+
}
393+
386394
return Napi::Buffer<uint8_t>::Copy(env, &closure->vec[0], closure->vec.size());
387395
}
388396

0 commit comments

Comments
 (0)