image-rs / weezl

LZW en- and decoding that goes weeeee!
Apache License 2.0
25 stars 7 forks source link

New lzw encoder creates invalid streams #18

Closed kornelski closed 3 years ago

kornelski commented 3 years ago

Encoding of large-ish images results in GIF images that look broken.

For example re-encoding of this image:

test-input

gives this file:

test-output

(Firefox refuses to render it. Chrome and macOS render only 20-something lines and garbage pixels.)

It's easy to reproduce with the example code. I've verified using another codebase that it's a bug in the GIF encoder, not the reader. The bug is in v0.11. It's not in v0.10.

HeroicKatora commented 3 years ago

Thanks for the report. Seems like the fault is on weezl here for any bit width smaller than 8.

HeroicKatora commented 3 years ago

I'm right now even fearing that we are facing miscompilation. Adding dbg!() to some statements or even just recompiling with a different compiler version seems to influence the output while the debugging code shows the exact same codes being encoded. There is no unsafe code anywhere.