Repository navigation
PluginBMP: 32-bit bound for RLE4 pixel count (stacked on #216) - #221
Merged
Merged
Conversation
Follow-up to the CVE-2023-47994 fix. Widening width * height to size_t only prevents the wrap where size_t is 64 bits. On 32-bit targets (Win32, MinGW32, armv7, wasm32) (size_t)0x40000001 * 4 still wraps to 4. Reject the dimensions when the product does not fit in size_t. In practice the caller's DIB allocation (about width * height / 2 bytes, overflow-checked in FreeImage_GetInternalImageSize) has to succeed first, which needs roughly 2 GB contiguous in a 32-bit process. So this is defence in depth that no longer depends on allocator limits. Also drop the bounds check in the 4-bit conversion loop. src - pixels is y * width with y < height, so src - pixels + width never exceeds pixel_count and the check could not fire. A truncated stream leaves the memset zeros in place; it does not move src.
danoli3
force-pushed
the
fix/bmp-rle4-size-overflow-32bit
branch
from
October 27, 2026 12:36
a55cdc5 to
5be4529
Compare
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.
Stacked on #216. This branch contains #216's commit (a8c20af, authorship kept) plus one follow-up commit. Merge it with a merge commit, not squash or rebase. That puts #216's head commit on
masterunchanged, so GitHub marks #216 as merged with its author credited.Change on top of #216
(size_t)width * (size_t)heightonly stops the wrap wheresize_tis 64 bits. On Win32, MinGW32, armv7 and wasm32,0x40000001 * 4still wraps to4. Dimensions whose product does not fit insize_tare now rejected:width * height / 2bytes, overflow-checked inFreeImage_GetInternalImageSize) has to be allocated first. That needs roughly 2 GB contiguous in a 32-bit process. So this is defence in depth rather than a demonstrated 32-bit exploit.src - pixels == y * widthwithy < height, so+ width <= pixel_countalways holds. A truncated stream leaves thememsetzeros in place; it never movessrc.On 64-bit, behaviour is identical to #216.
Verification (macOS arm64)
Standalone harness with a crafted in-memory RLE4 BMP:
8fea9cd)12 34 / 55 5512 34 / 55 55width=0x40000001, height=4The full
ctestsuite passes (11/11) under ASan + UBSan. The 32-bit path itself relies on the MinGW32 and armeabi-v7a CI jobs compiling it; neither job can practically reach it, for the allocation reason above.