Skip to content

Guard GIF LZW decoder against next_code overflow#329

Merged
mlarouche merged 1 commit into
zigimg:masterfrom
SAY-5:fix-gif-lzw-next-code-overflow
Jun 5, 2026
Merged

Guard GIF LZW decoder against next_code overflow#329
mlarouche merged 1 commit into
zigimg:masterfrom
SAY-5:fix-gif-lzw-next-code-overflow

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Some GIFs (about 1 in 10 from Giphy's search API, per #319) contain LZW data that keeps assigning new codes without ever sending a clear code. The decoder kept incrementing next_code past the 12-bit maximum, overflowing the u13 and panicking in decode. This stops adding dictionary entries once the table is full (4096 entries) and treats the unrecoverable KwKwK case at a full table as invalid data, which gif.zig already maps to InvalidData. Added a regression test that feeds such a stream and previously crashed at the same line as the report.

Fixes #319

… clear code

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@mlarouche mlarouche merged commit 4cab5a1 into zigimg:master Jun 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integer overflow panic while decoding gif

2 participants