Skip to content

Commit 3c6f205

Browse files
committed
Fixed bug 4500 - Heap-Buffer Overflow in Map1toN pertaining to SDL_pixels.c
Petr Pisar The reproducer has these data in BITMAPINFOHEADER: biSize = 40 biBitCount = 8 biClrUsed = 131075 SDL_LoadBMP_RW() function passes biBitCount as a color depth to SDL_CreateRGBSurface(), thus 256-color pallete is allocated. But then biClrUsed colors are read from a file and stored into the palette. SDL_LoadBMP_RW should report an error if biClrUsed is greater than 2^biBitCount.
1 parent 7964e0a commit 3c6f205

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/video/SDL_bmp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ SDL_Surface * SDL_LoadBMP_RW (SDL_RWops *src, int freesrc)
233233
if ( palette ) {
234234
if ( biClrUsed == 0 ) {
235235
biClrUsed = 1 << biBitCount;
236+
} else if ( biClrUsed > (1 << biBitCount) ) {
237+
SDL_SetError("BMP file has an invalid number of colors");
238+
was_error = SDL_TRUE;
239+
goto done;
236240
}
237241
if ( biSize == 12 ) {
238242
for ( i = 0; i < (int)biClrUsed; ++i ) {

0 commit comments

Comments
 (0)