google / wuffs

Wrangling Untrusted File Formats Safely
Other
4.06k stars 129 forks source link

PNG out-of-range palette indices #75

Open randy408 opened 2 years ago

randy408 commented 2 years ago

I haven't looked too much into it but my initial tests with spngt on the two images at https://github.com/w3c/PNG-spec/issues/96 appear to not decode with wuffs, probably because the out-of-range values are handled as an error, might want to change it to match libpng's defaults.

nigeltao commented 2 years ago

appear to not decode with wuffs

Can you share the code that leads to this conclusion?

https://github.com/google/wuffs/blob/a55e0a02a2befbd110dd2b76300b4f1caf3d3840/std/png/decode_png.wuffs#L863-L870 explicitly fills out-of-range palette entries to opaque black.

After running ./build-example.sh example/imageviewer from the Wuffs directory, the gen/bin/example-imageviewer X11 GUI program (which exercises Wuffs' PNG decoder) seems to agree with the https://github.com/w3c/PNG-spec/issues/96 original post: gray border, opaque black top and (opaque blue | transparent) bottom. Use the comma key, in gen/bin/example-imageviewer, to cycle the background color (which shows through transparent pixels).