Skip to content

fix stack overflow in GIF decoder (issue #1935)#1941

Open
im-lunex wants to merge 3 commits into
nothings:masterfrom
im-lunex:fix-#1935
Open

fix stack overflow in GIF decoder (issue #1935)#1941
im-lunex wants to merge 3 commits into
nothings:masterfrom
im-lunex:fix-#1935

Conversation

@im-lunex

Copy link
Copy Markdown

recursive stbi__out_gif_code() can overflow the stack on deeply
chained LZW codes (up to 4096). This happens easily on platforms with
small stacks like WebAssembly.

Fix: replaced the recursive traversal with an explicit loop that
walks the prefix chain and stores suffixes in a temporary buffer[4096],
then emits them in reverse order. No change to output or behavior.

Tested:

Closes #1935.

im-lunex added 3 commits April 23, 2026 21:22
…othings#1936)): Prevent integer overflows when processing large 16-bit PNG images by

validating allocation sizes with stbi__mad3sizes_valid before calling
malloc in stbi__convert_format16, stbi__convert_16_to_8, and
stbi__convert_8_to_16

add size-validations in stb_image.h

fixes nothings#1936
…othings#1936)): Prevent integer overflows when processing large 16-bit PNG images by

validating allocation sizes with stbi__mad3sizes_valid before calling
malloc in stbi__convert_format16, stbi__convert_16_to_8, and
stbi__convert_8_to_16

Fixes nothings#1936
…e the recursive stbi__out_gif_code() with an iterative

loop that stores suffix bytes in a small fixed-size buffer and
then emits them in reverse order. this prevents a stack overflow
(issue nothings#1935)
@im-lunex
im-lunex changed the base branch from master to dev April 26, 2026 05:28
@im-lunex
im-lunex changed the base branch from dev to master April 26, 2026 05:52
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.

stb_image: stack overflow in GIF decoder via deep LZW prefix chain

1 participant