CVE-2019-7578: Fix a buffer overread in InitIMA_ADPCM SDL-1.2
authorPetr Písař <ppisar@redhat.com>
Sat, 08 Jun 2019 18:02:09 -0700
branchSDL-1.2
changeset 12801388987dff7bf
parent 12800 e52413f52586
child 12815 a6e3d2f5183e
CVE-2019-7578: Fix a buffer overread in InitIMA_ADPCM
If IMA ADPCM format chunk was too short, InitIMA_ADPCM() parsing it
could read past the end of chunk data. This patch fixes it.

CVE-2019-7578
https://bugzilla.libsdl.org/show_bug.cgi?id=4494

Signed-off-by: Petr Písař <ppisar@redhat.com>
src/audio/SDL_wave.c
     1.1 --- a/src/audio/SDL_wave.c	Sat Jun 08 17:57:43 2019 -0700
     1.2 +++ b/src/audio/SDL_wave.c	Sat Jun 08 18:02:09 2019 -0700
     1.3 @@ -222,11 +222,12 @@
     1.4  	struct IMA_ADPCM_decodestate state[2];
     1.5  } IMA_ADPCM_state;
     1.6  
     1.7 -static int InitIMA_ADPCM(WaveFMT *format)
     1.8 +static int InitIMA_ADPCM(WaveFMT *format, int length)
     1.9  {
    1.10 -	Uint8 *rogue_feel;
    1.11 +	Uint8 *rogue_feel, *rogue_feel_end;
    1.12  
    1.13  	/* Set the rogue pointer to the IMA_ADPCM specific data */
    1.14 +	if (length < sizeof(*format)) goto too_short;
    1.15  	IMA_ADPCM_state.wavefmt.encoding = SDL_SwapLE16(format->encoding);
    1.16  	IMA_ADPCM_state.wavefmt.channels = SDL_SwapLE16(format->channels);
    1.17  	IMA_ADPCM_state.wavefmt.frequency = SDL_SwapLE32(format->frequency);
    1.18 @@ -235,11 +236,16 @@
    1.19  	IMA_ADPCM_state.wavefmt.bitspersample =
    1.20  					 SDL_SwapLE16(format->bitspersample);
    1.21  	rogue_feel = (Uint8 *)format+sizeof(*format);
    1.22 +	rogue_feel_end = (Uint8 *)format + length;
    1.23  	if ( sizeof(*format) == 16 ) {
    1.24  		rogue_feel += sizeof(Uint16);
    1.25  	}
    1.26 +	if (rogue_feel + 2 > rogue_feel_end) goto too_short;
    1.27  	IMA_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1]<<8)|rogue_feel[0]);
    1.28  	return(0);
    1.29 +too_short:
    1.30 +	SDL_SetError("Unexpected length of a chunk with an IMA ADPCM format");
    1.31 +	return(-1);
    1.32  }
    1.33  
    1.34  static Sint32 IMA_ADPCM_nibble(struct IMA_ADPCM_decodestate *state,Uint8 nybble)
    1.35 @@ -471,7 +477,7 @@
    1.36  			break;
    1.37  		case IMA_ADPCM_CODE:
    1.38  			/* Try to understand this */
    1.39 -			if ( InitIMA_ADPCM(format) < 0 ) {
    1.40 +			if ( InitIMA_ADPCM(format, lenread) < 0 ) {
    1.41  				was_error = 1;
    1.42  				goto done;
    1.43  			}