node-imagemagick-native icon indicating copy to clipboard operation
node-imagemagick-native copied to clipboard

is using Nan:NewBuffer safe in WrapPointer

Open x000zh opened this issue 8 years ago • 2 comments

when i try these code:

var fs = require('fs');
var imagemagick = require('./node-imagemagick-native');

imagemagick.convert({
     srcData: fs.readFileSync('./img.png')
     ,height: 100
     ,width: 100
}, function(err, buf){
     console.log(buf);
     setTimeout(function(){
         console.log(buf);
     }, 0);
});

the second console.log's output is very strange, it show that all zero in the buf.

platform: ubuntu 12.04 node: v4.2.2

I think, it maybe related to the imporper use of the Nan:NewBuffer

void wrap_pointer_cb(char *data, void *hint) {}

inline Local<Value> WrapPointer(char *ptr, size_t length) {
    Nan::EscapableHandleScope scope;
    return scope.Escape(Nan::NewBuffer(ptr, length, wrap_pointer_cb, NULL).ToLocalChecked());
}
   argv[1] = WrapPointer((char *)context->dstBlob.data(), context->dstBlob.length());

according to http://www.imagemagick.org/api/Magick++/Blob_8cpp_source.html https://github.com/nodejs/nan/blob/master/doc/buffers.md

it is not very safe to using Nan::NewBuffer take the ownership of the Blob::data(), however it shoud be more efficient than using Nan::CopyBuffer instead.

we didn't have the problem when we used node v.0.10.48. now we're migrating to v4.2.2.

I wonder if I could do something to avoid this problem, I prefer not to use Nan::CopyBuffer too.

x000zh avatar Nov 23 '15 05:11 x000zh

I have a similar trouble in platform: Amazon Linux AMI release 2015.09 node: v4.2.2

sapics avatar Nov 24 '15 01:11 sapics

May be the same problem that #118?

cartuchogl avatar Feb 14 '16 01:02 cartuchogl