Fixed bug 4500 - Heap-Buffer Overflow in Map1toN pertaining to SDL_pixels.c SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Mon, 18 Feb 2019 07:48:23 -0800
branchSDL-1.2
changeset 1261119d8c3b9c251
parent 12537 8586f153eede
child 12645 08f3b4992538
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.
src/video/SDL_bmp.c
     1.1 --- a/src/video/SDL_bmp.c	Sun Jan 13 15:27:50 2019 +0100
     1.2 +++ b/src/video/SDL_bmp.c	Mon Feb 18 07:48:23 2019 -0800
     1.3 @@ -233,6 +233,10 @@
     1.4  	if ( palette ) {
     1.5  		if ( biClrUsed == 0 ) {
     1.6  			biClrUsed = 1 << biBitCount;
     1.7 +		} else if ( biClrUsed > (1 << biBitCount) ) {
     1.8 +			SDL_SetError("BMP file has an invalid number of colors");
     1.9 +			was_error = SDL_TRUE;
    1.10 +			goto done;
    1.11  		}
    1.12  		if ( biSize == 12 ) {
    1.13  			for ( i = 0; i < (int)biClrUsed; ++i ) {