CVE-2019-7572: Fix a buffer overwrite in IMA_ADPCM_decode SDL-1.2
authorPetr Písař <ppisar@redhat.com>
Mon, 10 Jun 2019 08:57:11 -0700
branchSDL-1.2
changeset 12818a8afedbcaea0
parent 12817 faf9abbcfb5f
child 12819 fcbecae42795
CVE-2019-7572: Fix a buffer overwrite in IMA_ADPCM_decode
If data chunk was longer than expected based on a WAV format
definition, IMA_ADPCM_decode() tried to write past the output
buffer. This patch fixes it.

Based on patch from
<https://bugzilla.libsdl.org/show_bug.cgi?id=4496>.

CVE-2019-7572
https://bugzilla.libsdl.org/show_bug.cgi?id=4495

Signed-off-by: Petr Písař <ppisar@redhat.com>
src/audio/SDL_wave.c
     1.1 --- a/src/audio/SDL_wave.c	Mon Jun 10 08:54:29 2019 -0700
     1.2 +++ b/src/audio/SDL_wave.c	Mon Jun 10 08:57:11 2019 -0700
     1.3 @@ -346,7 +346,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, *encoded_end, *decoded;
     1.8 +	Uint8 *freeable, *encoded, *encoded_end, *decoded, *decoded_end;
     1.9  	Sint32 encoded_len, samplesleft;
    1.10  	unsigned int c, channels;
    1.11  
    1.12 @@ -373,6 +373,7 @@
    1.13  		return(-1);
    1.14  	}
    1.15  	decoded = *audio_buf;
    1.16 +	decoded_end = decoded + *audio_len;
    1.17  
    1.18  	/* Get ready... Go! */
    1.19  	while ( encoded_len >= IMA_ADPCM_state.wavefmt.blockalign ) {
    1.20 @@ -392,6 +393,7 @@
    1.21  			}
    1.22  
    1.23  			/* Store the initial sample we start with */
    1.24 +			if (decoded + 2 > decoded_end) goto invalid_size;
    1.25  			decoded[0] = (Uint8)(state[c].sample&0xFF);
    1.26  			decoded[1] = (Uint8)(state[c].sample>>8);
    1.27  			decoded += 2;
    1.28 @@ -402,6 +404,8 @@
    1.29  		while ( samplesleft > 0 ) {
    1.30  			for ( c=0; c<channels; ++c ) {
    1.31  				if (encoded + 4 > encoded_end) goto invalid_size;
    1.32 +				if (decoded + 4 * 4 * channels > decoded_end)
    1.33 +					goto invalid_size;
    1.34  				Fill_IMA_ADPCM_block(decoded, encoded,
    1.35  						c, channels, &state[c]);
    1.36  				encoded += 4;