src/video/SDL_bmp.c
branchSDL-1.2
changeset 12831 f1f5878be5db
parent 12722 33940ce0a0ba
child 12960 ad1bbfbca760
     1.1 --- a/src/video/SDL_bmp.c	Mon Jun 10 09:25:05 2019 -0700
     1.2 +++ b/src/video/SDL_bmp.c	Tue Jun 11 06:28:12 2019 -0700
     1.3 @@ -308,6 +308,12 @@
     1.4  				}
     1.5  				*(bits+i) = (pixel>>shift);
     1.6  				pixel <<= ExpandBMP;
     1.7 +				if ( bits[i] >= biClrUsed ) {
     1.8 +					SDL_SetError(
     1.9 +						"A BMP image contains a pixel with a color out of the palette");
    1.10 +					was_error = SDL_TRUE;
    1.11 +					goto done;
    1.12 +				}
    1.13  			} }
    1.14  			break;
    1.15  
    1.16 @@ -318,6 +324,16 @@
    1.17  				was_error = SDL_TRUE;
    1.18  				goto done;
    1.19  			}
    1.20 +			if ( 8 == biBitCount && palette && biClrUsed < (1 << biBitCount ) ) {
    1.21 +				for ( i=0; i<surface->w; ++i ) {
    1.22 +					if ( bits[i] >= biClrUsed ) {
    1.23 +						SDL_SetError(
    1.24 +							"A BMP image contains a pixel with a color out of the palette");
    1.25 +						was_error = SDL_TRUE;
    1.26 +						goto done;
    1.27 +					}
    1.28 +				}
    1.29 +			}
    1.30  #if SDL_BYTEORDER == SDL_BIG_ENDIAN
    1.31  			/* Byte-swap the pixels if needed. Note that the 24bpp
    1.32  			   case has already been taken care of above. */