File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -8,11 +8,13 @@ project adheres to [Semantic Versioning](http://semver.org/).
88(Unreleased)
99==================
1010### Changed
11+ * Allow larger buffers to be returned from ` toBuffer('raw') ` .
1112### Added
1213### Fixed
1314* Fix crash when changing canvas width/height while ` fillStyle ` or ` strokeStyle `
1415 was set to a ` CanvasPattern ` or ` CanvasGradient ` (#1357 ).
1516* Fix crash when changing width/height of SVG canvases (#1380 ).
17+ * Fix crash when using ` toBuffer('raw') ` with large canvases (#1158 ).
1618
17192.5.0
1820==================
Original file line number Diff line number Diff line change 2020#include < unordered_set>
2121#include " Util.h"
2222#include < vector>
23+ #include " node_buffer.h"
2324
2425#ifdef HAVE_JPEG
2526#include " JPEGStream.h"
@@ -413,8 +414,13 @@ NAN_METHOD(Canvas::ToBuffer) {
413414 if (info[0 ]->StrictEquals (Nan::New<String>(" raw" ).ToLocalChecked ())) {
414415 cairo_surface_t *surface = canvas->surface ();
415416 cairo_surface_flush (surface);
417+ if (canvas->nBytes () > node::Buffer::kMaxLength ) {
418+ Nan::ThrowError (" Data exceeds maximum buffer length." );
419+ return ;
420+ }
416421 const unsigned char *data = cairo_image_surface_get_data (surface);
417- Local<Object> buf = Nan::CopyBuffer (reinterpret_cast <const char *>(data), canvas->nBytes ()).ToLocalChecked ();
422+ Isolate* iso = Nan::GetCurrentContext ()->GetIsolate ();
423+ Local<Object> buf = node::Buffer::Copy (iso, reinterpret_cast <const char *>(data), canvas->nBytes ()).ToLocalChecked ();
418424 info.GetReturnValue ().Set (buf);
419425 return ;
420426 }
You can’t perform that action at this time.
0 commit comments