Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aborted when loading a specific png in ARM64 environments #3225

Closed
3 tasks done
tamaina opened this issue May 14, 2022 · 12 comments
Closed
3 tasks done

Aborted when loading a specific png in ARM64 environments #3225

tamaina opened this issue May 14, 2022 · 12 comments

Comments

@tamaina
Copy link

tamaina commented May 14, 2022

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 5.13 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (4) arm64 Neoverse-N1
    Memory: 20.15 GB / 23.31 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 18.1.0 - /usr/bin/node
    npm: 8.8.0 - /usr/bin/npm
  npmPackages:
    sharp: ^0.30.4 => 0.30.4 

(Oracle Cloud Infrastructure A1 instance)

What are the steps to reproduce?

Download PixelFed's favicon.png: https://pixelfed.tokyo/img/favicon.png?v=2
favicon

Load...

await sharp('favicon.png').toBuffer();

It throws error.
This error kills our software.

malloc(): corrupted top size
Aborted (core dumped)

What is the expected behaviour?

No error and no killing

@tamaina
Copy link
Author

tamaina commented May 14, 2022

Information:

It happens with sharp 0.30.0 or later.

Using libjemalloc2 resolves this error but I hope it will work without any manipulation on our part.
https://misskey.xianon.net/notes/8zrrs9qm9c

@tamaina tamaina changed the title Aborted when loading a specific png in ARM64 environment Aborted when loading a specific png in ARM64 environments May 14, 2022
@lovell
Copy link
Owner

lovell commented May 15, 2022

Thanks for reporting this, I'll try to reproduce on some ARM64 hardware when I can.

Please can you test the following code with the same image to help narrow down if this might be a decode or encode problem.

await sharp('favicon.png').raw().toBuffer(); // decode only, no PNG encoding

sharp v0.29.x provides libspng v0.6.3 whereas sharp v.30.x provides libspng v0.7.1.

The sample input is palette-based, and when decoded on ARM64 will use libspng v0.7.1's NEON optimised path, which leads me to suspect this might relate to randy408/libspng#189

@tamaina
Copy link
Author

tamaina commented May 15, 2022

Thanks for your reply.
It aborts as well in decode only.

image

@kleisauke
Copy link
Contributor

I was able to reproduce this crash with the libvips v8.12.2-build2 Windows ARM64 binaries on my Raspberry Pi 4B by simply doing:

vips.exe avg favicon.png

Doing the same with the (unpublished) v8.12.2 binaries, built against libspng 0.7.2, works without problems.

While looking at the temporary fix (commit randy408/libspng@a4270af), I noticed that only expand_palette_rgb8_neon was disabled in libspng 0.7.1. Given that this is a palettized RGBA8 PNG image, see:

$ vipsheader favicon.png
favicon.png: 153x152 uchar, 4 bands, srgb, pngload
$ vipsheader -f palette-bit-depth favicon.png
8

I think expand_palette_rgba8_neon also suffered from the same bug (randy408/libspng#188). The fix available in libspng 0.7.2 (commit randy408/libspng@f1c7735), fixed this for both expand_palette_rgb8_neon and expand_palette_rgba8_neon functions.

@randy408
Copy link

randy408 commented May 17, 2022

I think expand_palette_rgba8_neon also suffered from the same bug

This is confirmed to be the case. When the quickfix was released the root cause was not yet known, the image from the initial bug report did not trigger the same problem in the other function. It does with this new image.

The last release in February fixed both functions and also another issue that is listed in the announcement, so there was good reason to upgrade to the latest version, as it already declared the previous version (v0.7.1) buggy for other reasons.

@lovell
Copy link
Owner

lovell commented May 19, 2022

Thanks all for confirming, the future v0.31.0 release of sharp will provide prebuilt binaries with a more recent version of libspng with the fix.

@maximeg
Copy link

maximeg commented May 24, 2022

In the meantime, pinning to "sharp": "0.30.1" in resolutions avoids the crash for me.

@ngladbach
Copy link

Same problem here on M1 Mac, fixing version to 0.29.3 helped. In my case it influences NextJS and the upload-plugin of Strapi.

@Lambdac0re
Copy link

Fixing version to 0.29.3 helps on aarch64 fedora

@oebilgen
Copy link

All versions above 0.28.3 crash on Windows 11, Intel i7-11800H with this error. Try/catch doesn't work; the error takes the node process down (not sure how?).

@lovell
Copy link
Owner

lovell commented Aug 13, 2022

@oebilgen This issue relates only to ARM64. If you're seeing it on Intel hardware, please open a new issue and provide as much information as possible, including sample code with appropriate error handling, sample images, and ideally a backtrace of the crash.

@lovell
Copy link
Owner

lovell commented Sep 5, 2022

v0.31.0 now available with prebuilt binaries that contain the upstream fix, thanks all for reporting/helping with this.

@lovell lovell closed this as completed Sep 5, 2022
rabidaudio added a commit to fixdauto/webpack-image-resize-loader that referenced this issue Nov 9, 2022
solves this issue which was happening in docker containers on ARM cpus (M1 mac): lovell/sharp#3225
patrick11514 added a commit to patrick11514/MinonkaBot that referenced this issue Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants