GoogleChromeLabs / squoosh

Make images smaller using best-in-class codecs, right in the browser.
https://squoosh.app
Apache License 2.0
21.9k stars 1.54k forks source link

AVIF Encoder crashes with this image #807

Closed surma closed 3 years ago

surma commented 4 years ago
  1. Download this image (full resolution): https://unsplash.com/photos/inX5GIDNfAs
  2. Use default AVIF encoder settings
  3. See it crash.
GitHub-hosted copy: ![marcos-moraes-inX5GIDNfAs-unsplash (1)](https://user-images.githubusercontent.com/234957/91308808-b6c2dd00-e7a7-11ea-9fbb-47c73097fb7f.jpg)
jakearchibald commented 4 years ago

It works if you scale it down a bit, so I suspect this is a memory issue.

a1xon commented 4 years ago

index.tsx:479 Error: Encoding error with this image little-john-lPBpz4ePiMc-unsplash

jakearchibald commented 4 years ago

@a1xon thank you!

RReverser commented 4 years ago

Odd, the -s ALLOW_MEMORY_GROWTH=1 is used, so OOM shouldn't be a problem. Unless the encoder genuinely exceeds 2GB (the default allowed maximum).

It's spooky if so, but might be worth trying to add -s MAXIMUM_MEMORY=4GB here https://github.com/GoogleChromeLabs/squoosh/blob/4768bc17ba7949e569753680eb5b90853d0c1ac3/codecs/avif/Makefile#L25 to up the output to the newly supported limit (https://v8.dev/blog/4gb-wasm-memory#trying-it-out).

If that doesn't help, then it's likely a different kind of issue.

atjn commented 4 years ago

I am able to encode the image provided by surma without issue.

However, while trying to encode several different images, my page has crashed with SBOX_FATAL_MEMORY_EXCEEDED. I am not able to isolate any particular scenario that always crashes the page, but it happens more often on larger images with higher quality settings. Definetely seems like a memory issue to me.

This is in Chrome 85.0.4183.83 on Windows 10 2004

RReverser commented 4 years ago

Yeah if it's OOM then the only thing we can do is increase to a 4GB limit and hope that the upstream encoder gets better optimisations over time.

wojtekmaj commented 3 years ago

Is there anything the community could help with to push the fix forward?

surma commented 3 years ago

@wojtekmaj If you can reproduce the bug, you could try adding -s MAXIMUM_MEMORY=4GB to the AVIF Makefile and rebuild the codec, as @RReverser outlined. If that fixes the bug, we’d be happy to merge that PR.

RReverser commented 3 years ago

We've had some AVIF updates since. I've rechecked and, at least on a laptop and on default settings, the images above compress successfully now.

It's still possible for AVIF or any other codec to run out of memory on even larger images, but I think we can close this issue for now.