sharp icon indicating copy to clipboard operation
sharp copied to clipboard

BUG: '.metadata()' call hangs and crashes electron.

Open flynx opened this issue 3 months ago • 8 comments

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

  • [x] Running npm install sharp completes without error.
  • [x] Running node -e "require('sharp')" completes without error.

Are you using the latest version of sharp?

  • [x] I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

  System:
    OS: Linux 6.17 Fedora Linux 43 (Workstation Edition)
    CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
    Memory: 3.30 GB / 15.35 GB
    Container: Yes
    Shell: 5.3.0 - /bin/bash
  Binaries:
    Node: 22.20.0 - /usr/bin/node
    npm: 10.9.3 - /usr/bin/npm
  npmPackages:
    sharp: ^0.34.4 => 0.34.4 

Does this problem relate to file caching?

The default behaviour of libvips is to cache input files, which can lead to EBUSY or EPERM errors on Windows. Use sharp.cache(false) to switch this feature off.

  • [x] Adding sharp.cache(false) does not fix this problem.

Does this problem relate to images appearing to have been rotated by 90 degrees?

Images that contain EXIF Orientation metadata are not auto-oriented. By default, EXIF metadata is removed.

  • To auto-orient pixel values use the parameter-less rotate() operation.

  • To retain EXIF Orientation use keepExif().

  • [x] Using rotate() or keepExif() does not fix this problem.

What are the steps to reproduce?

'test.js':

require('sharp')('./image.png')
	.metadata()
        .then(
        	m => console.log('OK:', m),
        	e => console.log('ERR', e))

run in electron context:

npx electron ./text.js

The resulting process hangs then crashes with SIGSEGV

What is the expected behaviour?

Expected output:

OK: {
  format: 'png',
  width: 212,
  height: 48,
  space: 'srgb',
  channels: 4,
  depth: 'uchar',
  density: 72,
  isProgressive: false,
  isPalette: false,
  bitsPerSample: 8,
  hasProfile: false,
  hasAlpha: true,
  autoOrient: { width: 212, height: 48 }
}

Note that running the code in nodejs or in electrons repl works fine.

node ./test.js

or

npx electron -i

then

require('./test')

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem

https://gist.github.com/flynx/ed7ffbc9697586fa36ed416251826157


Originally posted to Electron's issue tracker: https://github.com/electron/electron/issues/48787

flynx avatar Nov 05 '25 18:11 flynx

Here's what I see locally:

$ npx electron --no-sandbox .
PRE
POST
[684686:1105/190012.405784:ERROR:content/browser/browser_main_loop.cc:278] GLib-GObject: g_object_ref: assertion 'G_IS_OBJECT (object)' failed
[684686:1105/190012.405814:ERROR:content/browser/browser_main_loop.cc:278] GLib-GObject: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
[684686:1105/190012.405822:ERROR:content/browser/browser_main_loop.cc:278] GLib-GObject: g_object_ref: assertion 'G_IS_OBJECT (object)' failed
[684686:1105/190012.405826:ERROR:content/browser/browser_main_loop.cc:278] GLib-GObject: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
[684686:1105/190012.405829:ERROR:content/browser/browser_main_loop.cc:278] GLib-GObject: g_object_ref: assertion 'G_IS_OBJECT (object)' failed
[684686:1105/190012.405832:ERROR:content/browser/browser_main_loop.cc:278] GLib-GObject: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
[684686:1105/190012.405860:ERROR:content/browser/browser_main_loop.cc:278] GLib-GObject: g_object_ref: assertion 'G_IS_OBJECT (object)' failed
[684686:1105/190012.405866:ERROR:content/browser/browser_main_loop.cc:278] GLib-GObject: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
[684686:1105/190012.405870:ERROR:content/browser/browser_main_loop.cc:278] GLib-GObject: g_object_ref: assertion 'G_IS_OBJECT (object)' failed
[684686:1105/190012.405875:ERROR:content/browser/browser_main_loop.cc:278] GLib-GObject: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
[684686:1105/190012.405892:ERROR:content/browser/browser_main_loop.cc:278] GLib-GObject: g_object_ref: assertion 'G_IS_OBJECT (object)' failed
[684686:1105/190012.405898:ERROR:content/browser/browser_main_loop.cc:278] GLib-GObject: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
[684686:1105/190012.405907:ERROR:content/browser/browser_main_loop.cc:278] GLib-GObject: g_object_ref: assertion 'G_IS_OBJECT (object)' failed
[684686:1105/190012.405911:ERROR:content/browser/browser_main_loop.cc:278] GLib-GObject: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
[684686:1105/190012.405937:ERROR:content/browser/browser_main_loop.cc:278] GLib-GObject: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
OK: {
  format: 'png',
  width: 212,
  height: 48,
  space: 'srgb',
  channels: 4,
  depth: 'uchar',
  density: 72,
  isProgressive: false,
  isPalette: false,
  bitsPerSample: 8,
  hasProfile: false,
  hasAlpha: true,
  autoOrient: { width: 212, height: 48 }
}
TIMEOUT

This is likely to relate to the perennial problem of the electron binary dynamically linking against a lot of system shared libraries (e.g. #2356, #4348, #4351).

$ ldd node_modules/electron/dist/electron 
	linux-vdso.so.1 (0x00007ffc3e62f000)
	libffmpeg.so => ./node_modules/electron/dist/libffmpeg.so (0x00007b7f84800000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007b7f90ca3000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007b7f90c9e000)
	libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007b7f846b7000)
	libgobject-2.0.so.0 => /lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007b7f84b9d000)
	libgio-2.0.so.0 => /lib/x86_64-linux-gnu/libgio-2.0.so.0 (0x00007b7f844e7000)
	libnspr4.so => /lib/x86_64-linux-gnu/libnspr4.so (0x00007b7f844a8000)
	libnss3.so => /lib/x86_64-linux-gnu/libnss3.so (0x00007b7f84379000)
	libnssutil3.so => /lib/x86_64-linux-gnu/libnssutil3.so (0x00007b7f84347000)
	libsmime3.so => /lib/x86_64-linux-gnu/libsmime3.so (0x00007b7f8431e000)
	libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007b7f842cf000)
	libatk-1.0.so.0 => /lib/x86_64-linux-gnu/libatk-1.0.so.0 (0x00007b7f842a5000)
	libatk-bridge-2.0.so.0 => /lib/x86_64-linux-gnu/libatk-bridge-2.0.so.0 (0x00007b7f84269000)
	libcups.so.2 => /lib/x86_64-linux-gnu/libcups.so.2 (0x00007b7f841c9000)
	libcairo.so.2 => /lib/x86_64-linux-gnu/libcairo.so.2 (0x00007b7f84085000)
	libgtk-3.so.0 => /lib/x86_64-linux-gnu/libgtk-3.so.0 (0x00007b7f83800000)
	libpango-1.0.so.0 => /lib/x86_64-linux-gnu/libpango-1.0.so.0 (0x00007b7f8401a000)
	libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007b7f836c3000)
	libXcomposite.so.1 => /lib/x86_64-linux-gnu/libXcomposite.so.1 (0x00007b7f90c93000)
	libXdamage.so.1 => /lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007b7f90c8e000)
	libXext.so.6 => /lib/x86_64-linux-gnu/libXext.so.6 (0x00007b7f84b89000)
	libXfixes.so.3 => /lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007b7f84b81000)
	libXrandr.so.2 => /lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007b7f8400d000)
	libgbm.so.1 => /lib/x86_64-linux-gnu/libgbm.so.1 (0x00007b7f84b7a000)
	libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007b7f83fe1000)
	libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007b7f8369a000)
	libxkbcommon.so.0 => /lib/x86_64-linux-gnu/libxkbcommon.so.0 (0x00007b7f83651000)
	libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 (0x00007b7f8361e000)
	libasound.so.2 => /lib/x86_64-linux-gnu/libasound.so.2 (0x00007b7f83514000)
	libatspi.so.0 => /lib/x86_64-linux-gnu/libatspi.so.0 (0x00007b7f834da000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007b7f833f1000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007b7f833c3000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007b7f83000000)
	/lib64/ld-linux-x86-64.so.2 (0x00007b7f90cc1000)
	libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007b7f83329000)
	libffi.so.8 => /lib/x86_64-linux-gnu/libffi.so.8 (0x00007b7f83fd5000)
	libgmodule-2.0.so.0 => /lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007b7f83fce000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007b7f8330d000)
	libmount.so.1 => /lib/x86_64-linux-gnu/libmount.so.1 (0x00007b7f832c0000)
	libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007b7f83293000)
	libplc4.so => /lib/x86_64-linux-gnu/libplc4.so (0x00007b7f8328a000)
	libplds4.so => /lib/x86_64-linux-gnu/libplds4.so (0x00007b7f83285000)
	libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007b7f82f20000)
	libgssapi_krb5.so.2 => /lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007b7f83231000)
	libavahi-common.so.3 => /lib/x86_64-linux-gnu/libavahi-common.so.3 (0x00007b7f83223000)
	libavahi-client.so.3 => /lib/x86_64-linux-gnu/libavahi-client.so.3 (0x00007b7f82f0d000)
	libgnutls.so.30 => /lib/x86_64-linux-gnu/libgnutls.so.30 (0x00007b7f82d13000)
	libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x00007b7f82cdb000)
	libfontconfig.so.1 => /lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007b7f82c8a000)
	libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007b7f82bbe000)
	libXrender.so.1 => /lib/x86_64-linux-gnu/libXrender.so.1 (0x00007b7f83213000)
	libxcb-render.so.0 => /lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007b7f82baf000)
	libxcb-shm.so.0 => /lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007b7f82baa000)
	libpixman-1.so.0 => /lib/x86_64-linux-gnu/libpixman-1.so.0 (0x00007b7f82afb000)
	libgdk-3.so.0 => /lib/x86_64-linux-gnu/libgdk-3.so.0 (0x00007b7f82a00000)
	libpangocairo-1.0.so.0 => /lib/x86_64-linux-gnu/libpangocairo-1.0.so.0 (0x00007b7f829ed000)
	libharfbuzz.so.0 => /lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x00007b7f828e0000)
	libpangoft2-1.0.so.0 => /lib/x86_64-linux-gnu/libpangoft2-1.0.so.0 (0x00007b7f828c5000)
	libfribidi.so.0 => /lib/x86_64-linux-gnu/libfribidi.so.0 (0x00007b7f828a7000)
	libcairo-gobject.so.2 => /lib/x86_64-linux-gnu/libcairo-gobject.so.2 (0x00007b7f8289b000)
	libgdk_pixbuf-2.0.so.0 => /lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007b7f8286d000)
	libepoxy.so.0 => /lib/x86_64-linux-gnu/libepoxy.so.0 (0x00007b7f82748000)
	libXi.so.6 => /lib/x86_64-linux-gnu/libXi.so.6 (0x00007b7f82735000)
	libthai.so.0 => /lib/x86_64-linux-gnu/libthai.so.0 (0x00007b7f8272a000)
	libdrm.so.2 => /lib/x86_64-linux-gnu/libdrm.so.2 (0x00007b7f82713000)
	libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007b7f8270d000)
	libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007b7f82703000)
	libcap.so.2 => /lib/x86_64-linux-gnu/libcap.so.2 (0x00007b7f826f6000)
	libblkid.so.1 => /lib/x86_64-linux-gnu/libblkid.so.1 (0x00007b7f826bb000)
	libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007b7f82573000)
	liblz4.so.1 => /lib/x86_64-linux-gnu/liblz4.so.1 (0x00007b7f82551000)
	liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007b7f8251d000)
	libzstd.so.1 => /lib/x86_64-linux-gnu/libzstd.so.1 (0x00007b7f82463000)
	libkrb5.so.3 => /lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007b7f8239a000)
	libk5crypto.so.3 => /lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007b7f8236e000)
	libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007b7f82368000)
	libkrb5support.so.0 => /lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007b7f82359000)
	libp11-kit.so.0 => /lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007b7f821b5000)
	libidn2.so.0 => /lib/x86_64-linux-gnu/libidn2.so.0 (0x00007b7f82193000)
	libunistring.so.5 => /lib/x86_64-linux-gnu/libunistring.so.5 (0x00007b7f81fe6000)
	libtasn1.so.6 => /lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007b7f81fd0000)
	libnettle.so.8 => /lib/x86_64-linux-gnu/libnettle.so.8 (0x00007b7f81f79000)
	libhogweed.so.6 => /lib/x86_64-linux-gnu/libhogweed.so.6 (0x00007b7f81f31000)
	libgmp.so.10 => /lib/x86_64-linux-gnu/libgmp.so.10 (0x00007b7f81ead000)
	libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007b7f81e99000)
	libbrotlidec.so.1 => /lib/x86_64-linux-gnu/libbrotlidec.so.1 (0x00007b7f81e8b000)
	libwayland-client.so.0 => /lib/x86_64-linux-gnu/libwayland-client.so.0 (0x00007b7f81e79000)
	libwayland-cursor.so.0 => /lib/x86_64-linux-gnu/libwayland-cursor.so.0 (0x00007b7f81e6f000)
	libwayland-egl.so.1 => /lib/x86_64-linux-gnu/libwayland-egl.so.1 (0x00007b7f81e6a000)
	libXcursor.so.1 => /lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007b7f81e5e000)
	libXinerama.so.1 => /lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007b7f81e59000)
	libgraphite2.so.3 => /lib/x86_64-linux-gnu/libgraphite2.so.3 (0x00007b7f81e31000)
	libjpeg.so.8 => /lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007b7f81dae000)
	libdatrie.so.1 => /lib/x86_64-linux-gnu/libdatrie.so.1 (0x00007b7f81da5000)
	libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007b7f81d8f000)
	libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007b7f81d6a000)
	libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007b7f81d61000)
	libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007b7f81d4e000)
	libbrotlicommon.so.1 => /lib/x86_64-linux-gnu/libbrotlicommon.so.1 (0x00007b7f81d2b000)
	libmd.so.0 => /lib/x86_64-linux-gnu/libmd.so.0 (0x00007b7f81d1c000)

Please see https://github.com/electron/electron/issues/46323

lovell avatar Nov 05 '25 19:11 lovell

Correction, turning off caching does not seem to have an effect, my mistake -- updated the main post.

flynx avatar Nov 05 '25 21:11 flynx

And for completeness, here is how a typical run on my system looks:

$ npx electron --no-sandbox .
PRE
POST
/home/f_lynx/work/ImageGrid/Viewer/test/bug-electron-sharp/node_modules/electron/dist/electron exited with signal SIGSEGV

flynx avatar Nov 05 '25 21:11 flynx

I have the same issue, node 24+ ....

  System:
    OS: Linux 5.10 Alpine Linux
    CPU: (2) x64 Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
    Memory: 7.00 GB / 7.65 GB
    Container: Yes
    Shell: Unknown - /bin/sh
  Binaries:
    Node: 24.11.1 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 11.6.2 - /usr/local/bin/npm
  npmPackages:
    sharp: ^0.34.4 => 0.34.5 

but it happens only in certain file types:

> file = fs.readFileSync("test.jpeg")
> await sharp(file).metadata()
{
  format: 'jpeg',
  size: 303839,
  width: 1280,
  height: 854,
  space: 'srgb',
  channels: 3,
  depth: 'uchar',
  density: 72,
  chromaSubsampling: '4:2:0',
  isProgressive: false,
  isPalette: false,
  hasProfile: false,
  hasAlpha: false,
  autoOrient: { width: 1280, height: 854 }
}
> file = fs.readFileSync("test.heic")
> await sharp(file).metadata()
Segmentation fault (core dumped)

Strnadj avatar Nov 14 '25 09:11 Strnadj

@Strnadj This issue relates to Electron, are you using Electron?

lovell avatar Nov 14 '25 09:11 lovell

@lovell no... I am not, but I am experiencing the same issue

Dockerfile

# Use the official Node.js image as the base image
FROM node:24-alpine AS build

# Set the working directory inside the container
WORKDIR /web

# Copy package.json and package-lock.json to the working directory
COPY package.json ./
COPY yarn.lock ./

# We need those to make node-gyp works, also to build sharp against vips
RUN apk add g++ make py3-pip

# For image processing (heic, tiff) - we need at least 8.17.3+ (so that's why edge)
RUN apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community build-base libheif vips-dev vips libde265-dev

# Install the application dependencies
RUN SHARP_FORCE_GLOBAL_LIBVIPS=true yarn install

# Copy the rest of the application files
COPY . .

# Build the app
RUN yarn build

Strnadj avatar Nov 14 '25 09:11 Strnadj

@Strnadj Please see https://wiki.alpinelinux.org/wiki/Repositories#Upgrading_to_edge

Warning: Do not enable Main/Community repositories from both stable release branch and edge at the same time. This can break your system. Either use edge or stable. If you mix stable and edge repositories, you're on your own.

If you're still having problems using Alpine stable OR edge (and not mixing the two) then create a new issue for this and provide sample image(s).

lovell avatar Nov 14 '25 09:11 lovell

@Strnadj Please see https://wiki.alpinelinux.org/wiki/Repositories#Upgrading_to_edge

Warning: Do not enable Main/Community repositories from both stable release branch and edge at the same time. This can break your system. Either use edge or stable. If you mix stable and edge repositories, you're on your own.

If you're still having problems using Alpine stable OR edge (and not mixing the two) then create a new issue for this and provide sample image(s).

Great point! Thank you, so I have to compile vips on stable and check that again... 🙏

Strnadj avatar Nov 14 '25 09:11 Strnadj

Please subscribe to https://github.com/electron/electron/issues/46323 for updates.

lovell avatar Dec 17 '25 16:12 lovell