Skip to content

Commit

Permalink
Fixed bug 4500 - Heap-Buffer Overflow in Map1toN pertaining to SDL_pi…
Browse files Browse the repository at this point in the history
…xels.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.
  • Loading branch information
slouken committed Feb 18, 2019
1 parent 7964e0a commit 3c6f205
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/video/SDL_bmp.c
Expand Up @@ -233,6 +233,10 @@ SDL_Surface * SDL_LoadBMP_RW (SDL_RWops *src, int freesrc)
if ( palette ) {
if ( biClrUsed == 0 ) {
biClrUsed = 1 << biBitCount;
} else if ( biClrUsed > (1 << biBitCount) ) {
SDL_SetError("BMP file has an invalid number of colors");
was_error = SDL_TRUE;
goto done;
}
if ( biSize == 12 ) {
for ( i = 0; i < (int)biClrUsed; ++i ) {
Expand Down

0 comments on commit 3c6f205

Please sign in to comment.