Closed
Description
Issue or Feature
Canvas's toBuffer method throws assertion error.
Steps to Reproduce
new (require('canvas').Canvas)(2e4, 2e4).toBuffer('raw');
Fix
NAN_METHOD(Canvas::ToBuffer)
from Canvas.cc
:
if (info.Length() >= 1 && info[0]->StrictEquals(Nan::New<String>("raw").ToLocalChecked())) {
// Return raw ARGB data -- just a memcpy()
cairo_surface_t *surface = canvas->surface();
cairo_surface_flush(surface);
const unsigned char *data = cairo_image_surface_get_data(surface);
+ if (canvas->nBytes() > 0x3fffffff)
+ return Nan::ThrowRangeError("Too large buffer");
Local<Object> buf = Nan::CopyBuffer(reinterpret_cast<const char*>(data), canvas->nBytes()).ToLocalChecked();
info.GetReturnValue().Set(buf);
return;
}
It should probably be done systematic in all places when the CopyBuffer
is called.
Your Environment
- Version of node-canvas: master
- Environment: node v10.0.0 on windows 8.1