CVE-2019-7574: Fix a buffer overread in IMA_ADPCM_decode SDL-1.2
authorPetr Písař <ppisar@redhat.com>
Mon, 10 Jun 2019 08:50:59 -0700
branchSDL-1.2
changeset 12815a6e3d2f5183e
parent 12801 388987dff7bf
child 12816 416136310b88
CVE-2019-7574: Fix a buffer overread in IMA_ADPCM_decode
If data chunk was shorter than expected based on a WAV format
definition, IMA_ADPCM_decode() tried to read past the data chunk
buffer. This patch fixes it.

CVE-2019-7574
https://bugzilla.libsdl.org/show_bug.cgi?id=4496

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 18:02:09 2019 -0700
     1.2 +++ b/src/audio/SDL_wave.c	Mon Jun 10 08:50:59 2019 -0700
     1.3 @@ -331,7 +331,7 @@
     1.4  static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
     1.5  {
     1.6  	struct IMA_ADPCM_decodestate *state;
     1.7 -	Uint8 *freeable, *encoded, *decoded;
     1.8 +	Uint8 *freeable, *encoded, *encoded_end, *decoded;
     1.9  	Sint32 encoded_len, samplesleft;
    1.10  	unsigned int c, channels;
    1.11  
    1.12 @@ -347,6 +347,7 @@
    1.13  	/* Allocate the proper sized output buffer */
    1.14  	encoded_len = *audio_len;
    1.15  	encoded = *audio_buf;
    1.16 +	encoded_end = encoded + encoded_len;
    1.17  	freeable = *audio_buf;
    1.18  	*audio_len = (encoded_len/IMA_ADPCM_state.wavefmt.blockalign) * 
    1.19  				IMA_ADPCM_state.wSamplesPerBlock*
    1.20 @@ -362,6 +363,7 @@
    1.21  	while ( encoded_len >= IMA_ADPCM_state.wavefmt.blockalign ) {
    1.22  		/* Grab the initial information for this block */
    1.23  		for ( c=0; c<channels; ++c ) {
    1.24 +			if (encoded + 4 > encoded_end) goto invalid_size;
    1.25  			/* Fill the state information for this block */
    1.26  			state[c].sample = ((encoded[1]<<8)|encoded[0]);
    1.27  			encoded += 2;
    1.28 @@ -384,6 +386,7 @@
    1.29  		samplesleft = (IMA_ADPCM_state.wSamplesPerBlock-1)*channels;
    1.30  		while ( samplesleft > 0 ) {
    1.31  			for ( c=0; c<channels; ++c ) {
    1.32 +				if (encoded + 4 > encoded_end) goto invalid_size;
    1.33  				Fill_IMA_ADPCM_block(decoded, encoded,
    1.34  						c, channels, &state[c]);
    1.35  				encoded += 4;
    1.36 @@ -395,6 +398,10 @@
    1.37  	}
    1.38  	SDL_free(freeable);
    1.39  	return(0);
    1.40 +invalid_size:
    1.41 +	SDL_SetError("Unexpected chunk length for an IMA ADPCM decoder");
    1.42 +	SDL_free(freeable);
    1.43 +	return(-1);
    1.44  }
    1.45  
    1.46  SDL_AudioSpec * SDL_LoadWAV_RW (SDL_RWops *src, int freesrc,