Closed CodeF53 closed 10 months ago
Thanks for the report @CodeF53. After playing around it seems like there might be an issue with the PNG decoding codec. Squoosh's implementation was quite basic and just repurposed the rust lib/png library.
When I find some time I'll see if I can find the exact error that is being reported in Rust and see if that helps us narrow it down. Alternatively, if you're running this code in the browser, you can likely utilize the Canvas API in the interim for a lightweight and faster png decoder to get the imagedata (See MDN docs).
So the PNG itself is technically corrupted. It has an invalid ICC PROFILE checksum (Also reported by the tool https://www.nayuki.io/page/png-file-chunk-inspector). However, most systems seem to ignore this and still render the image.
The rust error is:
CRC error: expected 0x768af32e have 0x723989cd while decoding ChunkType { type: iCCP, critical: false, private: false, reserved: false, safecopy: false } chunk.
I'll need to make some time to comeback to this and see how to ignore this checksum check. In the interim, you could try use an image editor to resave the PNG correctly.
(Repost because github mobile app showed I sent it twice. So I tried deleting the duplicate, only to have both comments dissappear. Thanks github mobile!)
I kind of expected it would be something like that, but thought it shouldn't matter because so many other applications don't seem to care.
I implemented a canvas based encode/decode fallback into my app for when this error occurs, but it is 10x slower than this library.
And that sucks because my app is used by people who aren't the person who made the images they are processing. So they have no clue their images could be improperly encoded. So my app just looks buggy/slow to them.
@CodeF53 I've released @jsquash/png@v3.0.0
which should now work with your broken pngs 👌
As it was going to require a major version release, I also included some other breaking changes. Please see the PR (#45) or Changelog file for details 🙇 .
Hope this helps with your app, happy new year! 🎉
@jamsinclair could you please double check your fix? Because in the same example: Reproduction - broken.png
decoding is fixed, but working.png
decoding now fails with the following error:
error: Uncaught (in promise) IndexSizeError: Failed to construct 'ImageData': The input data length is not equal to (4 width height).
Thanks for the report @DeniDoman. Not sure how this worked before... there now seems to be a bug with how we handle non-RGBA PNG files.
I'll have a fix ready shortly.
@DeniDoman, thanks for the wait! I believe version 3.0.1 should now fix the issue 🙌
Thanks for reporting the bug.
Thank you for the fix, @jamsinclair ! And huge thank you for the project overall, you rock!
@jamsinclair thanks for this great project! I'm using "@jsquash/png": "^3.0.1"
, but Error: 'unwrap_throw' failed
still exists, any updates?
Here is the png file:
Thanks @MeFelixWang, that appears to be because the file is actually a jpeg and not a png. It has been given the wrong file extension.
Reading the file with the UNIX file
command returns:
JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, progressive, precision 8, 640x451, components 3
I'll see if I can improve the error messaging 🤔
@jamsinclair thanks so much! I never thought about the extension. 😭
@MeFelixWang No worries, easy mistake. Happens to all of us! Best of luck with your project.
@jamsinclair Cheers for all the mistakes we made before! 😆
Describe the bug Given some
png
s, jsquash fails to decode and throws an error.To Reproduce Steps to reproduce the behavior:
broken.png
out of itbroken.png
's bufferdecode()
onbroken.png
bufferReproduction In this reproduction, there is 2 images,
working.png
andbroken.png
. The reproduction loads each image and attempts to decode it.Expected behavior
Actual behavior
Module Versions @jsquash/png 2.2.0 (latest)
Additional Context I have no reason to believe the
broken.png
in question has problematic encoding, as it functions perfectly with the following: