Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion error in Nan::CopyBuffer #1158

Closed
Hakerh400 opened this issue May 6, 2018 · 0 comments · Fixed by #1424
Closed

Assertion error in Nan::CopyBuffer #1158

Hakerh400 opened this issue May 6, 2018 · 0 comments · Fixed by #1424
Assignees
Labels

Comments

@Hakerh400
Copy link
Contributor

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
@zbjornson zbjornson added the Bug label Jun 15, 2018
@zbjornson zbjornson added this to To do in Ready issues Jan 13, 2019
zbjornson added a commit to zbjornson/node-canvas that referenced this issue May 11, 2019
Also allows larger buffers to be returned on 64-bit platforms. Nan only allows 0x3FFFFFFF; Node/v8 allows 0x7FFFFFFF on 64-bit.

Fixes Automattic#1158
@zbjornson zbjornson self-assigned this May 11, 2019
zbjornson added a commit to zbjornson/node-canvas that referenced this issue May 31, 2019
Also allows larger buffers to be returned on 64-bit platforms. Nan only allows 0x3FFFFFFF; Node/v8 allows 0x7FFFFFFF on 64-bit.

Fixes Automattic#1158
Ready issues automation moved this from To do to Done May 31, 2019
zbjornson added a commit that referenced this issue May 31, 2019
Also allows larger buffers to be returned on 64-bit platforms. Nan only allows 0x3FFFFFFF; Node/v8 allows 0x7FFFFFFF on 64-bit.

Fixes #1158
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Ready issues
  
Done
Development

Successfully merging a pull request may close this issue.

2 participants