fix: prevent integer overflow in 16-bit image conversions (#1936)#1940
Open
im-lunex wants to merge 2 commits into
Open
fix: prevent integer overflow in 16-bit image conversions (#1936)#1940im-lunex wants to merge 2 commits into
im-lunex wants to merge 2 commits into
Conversation
added 2 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
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.
In stbi__convert_format16, stbi__convert_16_to_8, and stbi__convert_8_to_16,
the size calculation
w * h * channels * 2can overflow a signed 32-bit int,leading to a buffer overflow. This fix adds a call to stbi__mad3sizes_valid
before each allocation to reject oversized images early.
Tested with:
fixes #1936