File tree 2 files changed +9
-1
lines changed
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/).
8
8
(Unreleased)
9
9
==================
10
10
### Changed
11
+ * Allow larger buffers to be returned from ` toBuffer('raw') ` .
11
12
### Added
12
13
### Fixed
13
14
* Fix crash when changing canvas width/height while ` fillStyle ` or ` strokeStyle `
14
15
was set to a ` CanvasPattern ` or ` CanvasGradient ` (#1357 ).
15
16
* Fix crash when changing width/height of SVG canvases (#1380 ).
17
+ * Fix crash when using ` toBuffer('raw') ` with large canvases (#1158 ).
16
18
17
19
2.5.0
18
20
==================
Original file line number Diff line number Diff line change 20
20
#include < unordered_set>
21
21
#include " Util.h"
22
22
#include < vector>
23
+ #include " node_buffer.h"
23
24
24
25
#ifdef HAVE_JPEG
25
26
#include " JPEGStream.h"
@@ -413,8 +414,13 @@ NAN_METHOD(Canvas::ToBuffer) {
413
414
if (info[0 ]->StrictEquals (Nan::New<String>(" raw" ).ToLocalChecked ())) {
414
415
cairo_surface_t *surface = canvas->surface ();
415
416
cairo_surface_flush (surface);
417
+ if (canvas->nBytes () > node::Buffer::kMaxLength ) {
418
+ Nan::ThrowError (" Data exceeds maximum buffer length." );
419
+ return ;
420
+ }
416
421
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 ();
418
424
info.GetReturnValue ().Set (buf);
419
425
return ;
420
426
}
You can’t perform that action at this time.
0 commit comments