Skip to content

Commit 6cf7de4

Browse files
authored
Merge pull request #221 from danoli3/fix/bmp-rle4-size-overflow-32bit
PluginBMP: 32-bit bound for RLE4 pixel count (stacked on #216)
2 parents 30d4b15 + 5be4529 commit 6cf7de4

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

‎Source/FreeImage/PluginBMP.cpp‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,9 @@ LoadPixelDataRLE4(FreeImageIO *io, fi_handle handle, int width, int height, FIBI
292292

293293
// NB: width and height are file-driven ints: multiply in size_t so a
294294
// huge image cannot wrap to a tiny buffer (CVE-2023-47994 integer
295-
// overflow in LoadPixelDataRLE4).
296-
if (width <= 0 || height <= 0) {
295+
// overflow in LoadPixelDataRLE4). size_t is only 32 bits on 32-bit
296+
// targets, so bound the product explicitly as well.
297+
if (width <= 0 || height <= 0 || (size_t)width > ((size_t)-1) / (size_t)height) {
297298
throw(1);
298299
}
299300
const size_t pixel_count = (size_t)width * (size_t)height;
@@ -395,11 +396,6 @@ LoadPixelDataRLE4(FreeImageIO *io, fi_handle handle, int width, int height, FIBI
395396
// Convert to 4-bit
396397
for(int y = 0; y < height; y++) {
397398
const BYTE *src = pixels + (size_t)y * (size_t)width;
398-
// NB: with a truncated stream src can run past the decoded
399-
// bytes: stop instead of reading out of bounds (CVE-2023-47994).
400-
if ((size_t)(src - pixels) + (size_t)width > pixel_count) {
401-
throw(1);
402-
}
403399
BYTE *dst = FreeImage_GetScanLine(dib, y);
404400

405401
BOOL hinibble = TRUE;

0 commit comments

Comments
 (0)