AnimatedGIFs_SD icon indicating copy to clipboard operation
AnimatedGIFs_SD copied to clipboard

Possible wrong buffer overrun detection during lzw_decode

Open alimbourg opened this issue 4 years ago • 4 comments

... Causing last pixel of every lines of non interlaced gifs to be glitchy.

When activating LZWDEBUG (=1) , serial monitor is reporting a lot of buffer overruns on very small gifs (8x8) (LzwDecoder_Impl.h/line 121)

It seems that decompressAndDisplayFrame() is subtracting one byte for the buffend parameters ( GifDecoder_Impl.h/line 869) while calling lzw_decode (although the inner code code seems not require that unless I'm missing something).

Changing the call into int len = lzw_decode(imageBuf + tbiImageX, tbiWidth, imageBuf + maxGifWidth, align); suppress the warning and decode the last pixel. Regards

alimbourg avatar Jan 11 '21 08:01 alimbourg

Sorry, I have not really done anything with this project recently.

The master Branch is out of date. I had been using adafruit_opt Branch.

I should tidy up the comments in the code and put it into the master Branch.

Please can you quote which Branch and which GIF is exhibiting the problem.

David.

prenticedavid avatar Jan 11 '21 12:01 prenticedavid

Sorry about that: so, previously tested on master, but the call to lzw_decode and the dubious bufend computation is similar in the adafruit_opt branch (GifDecoder_Impl.h/line 873)

Here is the tiny GIF showing a bizarre last pixel on each row when lzw_decode is leaving too early: ghosts_8x8

Regards

alimbourg avatar Jan 14 '21 08:01 alimbourg

Your Tiny gif is difficult to see on a PC screen. I copied it to the data directory of the AnimatedGIFS_SD sketch. Uploaded to SPIFFS

It was pretty small to see on a 135x240 ST7789 screen So I tried a 128x160 ST7735 screen where iit was still small.

Each frame on ESP32 seems to match the frame on my PC running EZGif

Ah-ha. I loaded the tiny.GIF into IrfanViiew. Frame #2 is 8x8 Blue. WxH Frame #3, 4, 5 seem to lose the last row i.e. 8x7 Red/Orange

I will investigate. Do you have a better example GIF ?

David.

prenticedavid avatar Jan 15 '21 12:01 prenticedavid

thank you @alimbourg, I had the same issue : last pixel of each line was background. This is solving my issue (on 16x16 gif)

pmerlin avatar Sep 29 '23 08:09 pmerlin