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
28.91k stars 1.29k forks source link

Errors with `.toFile()` and `.metadata()` with animated WEBP files #3077

Closed richardneililagan closed 2 years ago

richardneililagan commented 2 years ago

Multiple exceptions are encountered when working with animated WEBP files. So far tested with .toFile() and .metadata(), and both are throwing exceptions when working with an animated WEBP file, flagged with { animated: true }.


Are you using the latest version? Is the version currently in use as reported by npm ls sharp the same as the latest version as reported by npm view sharp dist-tags.latest?

Yes.


❯ npm ls sharp && npm view sharp dist-tags.latest
sharp-animated-webp-metadata@1.0.0 /redacted/dev/src/sharp-animated-webp-metadata
└── sharp@0.30.0

0.30.0


What are the steps to reproduce?

> 1. Prepare an animated WEBP file. (This was also tested with an image generated by [`gif2webp`](https://developers.google.com/speed/webp/docs/gif2webp).)
> 2. Wrap file in `sharp()` constructor, with `{ animated: true }`.
> 3. `await sharpInstance.metadata()` or `await sharpInstance.toFile(...)`
>
> Exception is thrown, citing:
> ```text
> [Error: Input file has corrupt header: webp: bad image dimensions]
> ```

What is the expected behaviour?

> `.metadata()` / `.toFile(...)` do not throw exceptions for a valid animated WEBP image.

Are you able to provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem?

> [Sure thing](https://github.com/richardneililagan/sharp-animated-webp-issue-demo).

Are you able to provide a sample image that helps explain the problem?

> [Absolutely](https://github.com/richardneililagan/sharp-animated-webp-issue-demo/tree/main/assets).

What is the output of running `npx envinfo --binaries --system`?

```text
  System:
    OS: Linux 5.11 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (2) arm64 unknown
    Memory: 757.72 MB / 3.77 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 16.13.0 - /tmp/fnm_multishells/937395_1644243262935/bin/node
    Yarn: 1.22.17 - /tmp/fnm_multishells/937395_1644243262935/bin/yarn
    npm: 8.1.0 - /tmp/fnm_multishells/937395_1644243262935/bin/npm
lovell commented 2 years ago

Hi, does this only occur on arm64? Are you able to reproduce on an x64 CPU? Are you using the prebuilt binaries?

richardneililagan commented 2 years ago

Yes to prebuilt binaries (afaik) --- is it just libvips that I need to check?

I'll give it a shot on an x64 later today. :)

richardneililagan commented 2 years ago

So it looks like your hunch was right --- an old version of libvips was present in the system, and somehow erroring out. Removing it (and re-adding sharp@0.30.0 into the project) solved the problem on the arm64.

Also tried it out on an x64, and it's working perfectly.

My bad, and thanks for your assistance! Feel free to close if you feel there isn't anything else we need to explore.