fix stack overflow in GIF decoder (issue #1935)#1941
Open
im-lunex wants to merge 3 commits into
Open
Conversation
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
recursive
stbi__out_gif_code()can overflow the stack on deeplychained 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:
stack‑limited Linux (ulimit -s 128) without crashing.
tests/stb_image_testpasses without regressions.Closes #1935.