Skip to content

Assertion error in Nan::CopyBuffer #1158

Closed
@Hakerh400

Description

@Hakerh400

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions