Twinside / Juicy.Pixels

Haskell library to load & save pictures
BSD 3-Clause "New" or "Revised" License
238 stars 57 forks source link

Distortion (and possibly segfault) in decoding a certain JPEG #205

Closed mtolly closed 2 years ago

mtolly commented 2 years ago

Tracking down a segfault in my app led me to the decoding of a specific JPEG, which I think may be invoking out of bounds or uninitialized memory access.

test

(I don't think GitHub reencoded this, but I can upload it elsewhere if needed)

Doing a simple decode/encode with 3.3.6, I get:

test

I wasn't able to get a demo program to crash at all (which just does the decode/encode), and my own app only crashes some of the time, possibly dependent on the memory layout beforehand. So I'm not 100% sure that the decoding is causing the segfault, but it seems plausible based on the half-gibberish decoded result.

Twinside commented 2 years ago

Ok, the jpeg format is a bit unusual, there is two vertical macroblock stacked, hence the proper rendering of half the lines of macro block

mtolly commented 2 years ago

Thank you for such a quick fix! Crash seems to be resolved completely 😄