lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.36k stars 1.3k forks source link

PNG Conversion Failure #4184

Closed stefanpieper closed 3 months ago

stefanpieper commented 3 months ago

Possible bug

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

If you cannot confirm both of these, please open an installation issue instead.

Are you using the latest version of sharp?

If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.

If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.

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

  System:
    OS: macOS 14.6
    CPU: (10) arm64 Apple M1 Max
    Memory: 54.48 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.12.2/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
    pnpm: 9.6.0 - ~/.nvm/versions/node/v20.12.2/bin/pnpm
  npmPackages:
    sharp: ^0.33.4 => 0.33.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.

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.

What are the steps to reproduce?

See attached archive with test code and data. The PNG test image is loaded and resized, then written to a buffer.

png-conversion-failure.zip

When executing the test code, this error is thrown:

Error: pngload_buffer: libspng read error
    at Sharp.toBuffer (/Users/spieper/src/phoenix.imts-library/png-conversion-failure/node_modules/sharp/lib/output.js:161:17)
    at pngConversionFailure (/Users/spieper/src/phoenix.imts-library/png-conversion-failure/png-conversion-failure.js:8:49)

What is the expected behaviour?

Process completes without error.

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

See attached archive.

Please provide sample image(s) that help explain this problem

See attached archive.

lovell commented 3 months ago

This looks like a corrupt/truncated PNG image. If you trust the source of this image, please see the failOn constructor property to relax how warnings and errors are handled.

https://sharp.pixelplumbing.com/api-constructor

// USE THIS FOR TRUSTED INPUT ONLY
sharp(input, { failOn: 'none' })...
stefanpieper commented 3 months ago

Thanks a lot for your quick help!