Skip to content

Commit

Permalink
Throw surface errors in toBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfedr authored and chearon committed Sep 27, 2024
1 parent efcde93 commit a2e10e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ This release notably changes to using N-API. 🎉
* Changed PNG consts to static properties of Canvas class
### Added
* Added string tags to support class detection
* Throw Cairo errors in canvas.toBuffer()
### Fixed
* Fix a case of use-after-free. (#2229)
* Fix usage of garbage value by filling the allocated memory entirely with zeros if it's not modified. (#2229)
Expand Down
10 changes: 9 additions & 1 deletion src/Canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,15 @@ Canvas::ToBuffer(const Napi::CallbackInfo& info) {
closure = static_cast<SvgBackend*>(backend())->closure();
}

cairo_surface_finish(surface());
cairo_surface_t *surf = surface();
cairo_surface_finish(surf);

cairo_status_t status = cairo_surface_status(surf);
if (status != CAIRO_STATUS_SUCCESS) {
Napi::Error::New(env, cairo_status_to_string(status)).ThrowAsJavaScriptException();
return env.Undefined();
}

return Napi::Buffer<uint8_t>::Copy(env, &closure->vec[0], closure->vec.size());
}

Expand Down

0 comments on commit a2e10e6

Please sign in to comment.