Automattic / node-canvas

Node canvas is a Cairo backed Canvas implementation for NodeJS.
10.14k stars 1.17k forks source link

node-canvas loads incorrect libcairo #1859

Open ejoebstl opened 3 years ago

ejoebstl commented 3 years ago

I am running into a segfault when trying to render a PDF using pdf.js onto a canvas instance.

I have tried to run node with GDB and this is the output. It seems like the segfault happens inside a libcairo that comes pre-bundled with another package.

free(): invalid pointer

Thread 1 "node" received signal SIGABRT, Aborted.
0x00007ffff7ab19e5 in raise () from /lib64/libc.so.6
(gdb) bt
#0  0x00007ffff7ab19e5 in raise () from /lib64/libc.so.6
#1  0x00007ffff7a9a8a4 in abort () from /lib64/libc.so.6
#2  0x00007ffff7af4007 in __libc_message () from /lib64/libc.so.6
#3  0x00007ffff7afbcdc in malloc_printerr () from /lib64/libc.so.6
#4  0x00007ffff7afd0ac in _int_free () from /lib64/libc.so.6
#5  0x00007fffd74780e5 in ?? ()
   from /home/emi/Projects/authory/api/node_modules/sharp/build/Release/../../vendor/lib/libcairo.so.2
#6  0x00007fffd747ae16 in ?? ()
   from /home/emi/Projects/authory/api/node_modules/sharp/build/Release/../../vendor/lib/libcairo.so.2
#7  0x00007fffd74e08c0 in ?? ()
   from /home/emi/Projects/authory/api/node_modules/sharp/build/Release/../../vendor/lib/libcairo.so.2
#8  0x00007fffd7483a58 in ?? ()
   from /home/emi/Projects/authory/api/node_modules/sharp/build/Release/../../vendor/lib/libcairo.so.2
#9  0x00007fffd747da71 in ?? ()
   from /home/emi/Projects/authory/api/node_modules/sharp/build/Release/../../vendor/lib/libcairo.so.2
#10 0x00007fffd74f09ca in cairo_paint_with_alpha ()
   from /home/emi/Projects/authory/api/node_modules/sharp/build/Release/../../vendor/lib/libcairo.so.2
#11 0x00007fffd4b16d1f in Context2d::DrawImage(Nan::FunctionCallbackInfo<v8::Value> const&) ()
   from /home/emi/Projects/authory/common/node_modules/node-canvas/build/Release/canvas.node
#12 0x00007fffd4b0b9f8 in Nan::imp::FunctionCallbackWrapper(v8::FunctionCallbackInfo<v8::Value> const&) ()
   from /home/emi/Projects/authory/common/node_modules/node-canvas/build/Release/canvas.node
[omitted]

When I remove the other package from the project, the code works normally.

How can I configure node-canvas to load the libcairo I have installed on my OS, or another version that is appropriate?

Environment

canvas@2.8.0 Fedora release 33 Node v12.22.1

zbjornson commented 3 years ago

I think this is a variation of #930. I haven't looked at the issue in a long time though. Node-canvas prebuilds use the latest versions of Cairo/etc., and it specifically loads the SOs that we bundle, so I'm not sure what the conflict is anymore.

ejoebstl commented 3 years ago

@zbjornson Gotcha. Do you have an idea or any pointer how to approach debugging this?