Skip to content

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

@flynx

Description

@flynx

Possible bug

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

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

Are you using the latest version of sharp?

  • 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.

  • 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().

  • 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:
electron/electron#48787

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions