Control: reassign -1 node-opencv Hi,
* Jérémy Lal <kapo...@melix.org> [2021-04-22 18:38]:
(gdb) bt #0 __memcpy_power7 () at ../sysdeps/powerpc/powerpc64/power7/memcpy.S:235 #1 0x00007ffff0145254 in memcpy (__len=4, __src=<optimized out>, __dest=0x7fffc779d480) at /usr/include/powerpc64le-linux-gnu/bits/string_fortified.h:34 #2 cv::PngDecoder::readDataFromBuf (_png_ptr=0x7fffb0000d20, dst=0x7fffc779d480 "\226\341l\204", size=4) at ../modules/imgcodecs/src/grfmt_png.cpp:138 #3 0x00007fffdb5799ac in png_read_data (png_ptr=<optimized out>, data=<optimized out>, length=<optimized out>) at pngrio.c:37 #4 0x00007fffdb581b2c in png_crc_error (png_ptr=0x7fffb0000d20) at pngrutil.c:275 #5 0x00007fffdb581c70 in png_crc_finish (png_ptr=0x7fffb0000d20, skip=<optimized out>) at pngrutil.c:229 #6 0x00007fffdb5882a8 in png_read_IDAT_data (png_ptr=0x7fffb0000d20, output=<optimized out>, avail_out=<optimized out>) at pngrutil.c:4351 #7 0x00007fffdb57608c in png_read_row (png_ptr=0x7fffb0000d20, row=0x7fffc697c300 "", dsp_row=0x0) at pngread.c:623 #8 0x00007fffdb5782d8 in png_read_image (png_ptr=0x7fffb0000d20, image=0x7fffb000b910) at pngread.c:833 #9 0x00007ffff0145fc8 in cv::PngDecoder::readData (this=0x7fffb0000c20, img=...) at ../modules/imgcodecs/src/grfmt_png.cpp:284 #10 0x00007ffff0128e4c in cv::imdecode_ (buf=..., flags=flags@entry=1, mat=...) at ../modules/imgcodecs/src/loadsave.cpp:860 #11 0x00007ffff0129a70 in cv::imdecode (_buf=..., flags=<optimized out>) at ../modules/imgcodecs/src/loadsave.cpp:900 #12 0x00007ffff0539ec8 in AsyncImDecodeWorker::Execute (this=0x100253b00) at /usr/include/opencv4/opencv2/core/mat.inl.hpp:92 #13 0x00007ffff0530ba4 in Nan::AsyncExecute (req=<optimized out>) at ../../../../usr/lib/nodejs/nan/nan.h:2284 #14 0x00007ffff60aac84 in uv__queue_work (w=<optimized out>) at ../deps/uv/src/threadpool.c:321 #15 0x00007ffff60aad9c in worker (arg=0x0) at ../deps/uv/src/threadpool.c:122 #16 0x00007ffff54a956c in start_thread (arg=0x7fffc779f140) at pthread_create.c:477 #17 0x00007ffff53b8044 in clone () at ../sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S:82
This is in the async version of node-opencv cleaning up the buffer during the memcpy. I was not able to reproduce it anymore with the attached hack (you probably want to commit a clean version).
Cheers Jochen
diff --git a/src/OpenCV.cc b/src/OpenCV.cc index b9f779c..f84f249 100755 --- a/src/OpenCV.cc +++ b/src/OpenCV.cc @@ -37,6 +37,7 @@ public: cv::Mat mbuf(len, 1, CV_64FC1, buf); outputmat = cv::imdecode(mbuf, flags); success = 1; + free(buf); } catch(...){ success = 0; } @@ -224,8 +225,10 @@ NAN_METHOD(OpenCV::ReadImageAsync) { // async uint8_t *buf = (uint8_t *) Buffer::Data(Nan::To<v8::Object>(info[0]).ToLocalChecked()); unsigned len = Buffer::Length(Nan::To<v8::Object>(info[0]).ToLocalChecked()); + uint8_t *buf_new = (uint8_t *)malloc(len); + memcpy(buf_new, buf, len); Nan::Callback *callback = new Nan::Callback(cb.As<Function>()); - Nan::AsyncQueueWorker(new AsyncImDecodeWorker(callback, buf, len, flags)); + Nan::AsyncQueueWorker(new AsyncImDecodeWorker(callback, buf_new, len, flags)); return; } // WILL have returned by here unless exception
signature.asc
Description: PGP signature