Repository navigation
PluginBMP: size_t arithmetic in LoadPixelDataRLE4 (CVE-2023-47994) - #216
Conversation
width/height are file-driven ints: width * height in int arithmetic overflows for huge images (UBSan: 4 * 1073741825), wrapping to a tiny pixels buffer while the 4-bit convert loop walks width * height bytes -> heap-buffer-overflow READ past the buffer. Compute the count in size_t, reject non-positive dimensions, and bound the convert loop (plus the delta/end-of-line pointer math) by the real buffer end so truncated streams stop instead of reading out of bounds. RED (UBSan signed-overflow + ASan heap-buffer-overflow READ with a 64-byte crafted RLE4 BMP, pre-fix) -> GREEN (post-fix) verified; valid RLE4/RLE8/RGB BMPs still decode pixel-identically. AI assistance disclosure: this patch was authored with AI assistance (agentic coding CLI) and verified with AddressSanitizer/UBSan red/green runs before submission.
|
Reviewed against current The core fix is right. Issues:
The Verdict: fixes the reported 64-bit crash, but it is not complete until the 32-bit overflow check from (1) is added. Please also remove or fix the dead guard from (2). |
|
Follow-up: #221 is stacked on this PR. It carries your commit unchanged plus the 32-bit bound, and it drops the conversion-loop guard that could never fire. Merging #221 with a merge commit lands your commit as-is and marks this PR as merged. A correction to my earlier review. I called the 32-bit overflow "blocking". It is real in the arithmetic, but in practice it's close to unreachable. The caller's DIB allocation (about I also confirmed your fix locally. Before it, |
|
Thanks for the follow-up and the correction on reachability. Happy with #221 carrying this commit unchanged plus the defence-in-depth bound — merging that with a merge commit works for me. The conversion-loop guard removal in #221 is also fine (agreed it could never fire once the RLE count is bounded). |
PluginBMP: 32-bit bound for RLE4 pixel count (stacked on #216)
|
Follow up merged! |

Root cause (CVE-2023-47994)
LoadPixelDataRLE4multiplies file-drivenint width * heightin int arithmetic. For huge dimensions this is signed overflow (UBSan pre-fix:signed integer overflow: 4 * 1073741825), wrapping to a tinypixelsbuffer while the 4-bit convert loop walks the fullwidth * heightrange -> heap-buffer-overflow READ past the buffer (ASan pre-fix trace, 64-byte crafted RLE4 BMP withwidth=0x40000001,height=4).Fix
pixel_countinsize_t, sizeendfrom it.scanline*widthpointer math) by the real buffer end so truncated streams stop with an error instead of reading out of bounds.CheckBitmapInfoHeader;height = abs(height)is now provably safe (top-down RLE4 never reaches here).Verification (ASan+UBSan, serial build)
imgPoC (negative width) stays clean-NULL via header validation.PoC repos used as reproducers only, never as patch sources.
AI assistance disclosure: this patch was authored with AI assistance (agentic coding CLI) and verified with AddressSanitizer/UBSan red/green runs before submission.