Skip to content

Commit f22cbe4

Browse files
committed
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>
1 parent 68f914a commit f22cbe4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/audio/SDL_wave.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static void Fill_IMA_ADPCM_block(Uint8 *decoded, Uint8 *encoded,
346346
static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
347347
{
348348
struct IMA_ADPCM_decodestate *state;
349-
Uint8 *freeable, *encoded, *encoded_end, *decoded;
349+
Uint8 *freeable, *encoded, *encoded_end, *decoded, *decoded_end;
350350
Sint32 encoded_len, samplesleft;
351351
unsigned int c, channels;
352352

@@ -373,6 +373,7 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
373373
return(-1);
374374
}
375375
decoded = *audio_buf;
376+
decoded_end = decoded + *audio_len;
376377

377378
/* Get ready... Go! */
378379
while ( encoded_len >= IMA_ADPCM_state.wavefmt.blockalign ) {
@@ -392,6 +393,7 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
392393
}
393394

394395
/* Store the initial sample we start with */
396+
if (decoded + 2 > decoded_end) goto invalid_size;
395397
decoded[0] = (Uint8)(state[c].sample&0xFF);
396398
decoded[1] = (Uint8)(state[c].sample>>8);
397399
decoded += 2;
@@ -402,6 +404,8 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
402404
while ( samplesleft > 0 ) {
403405
for ( c=0; c<channels; ++c ) {
404406
if (encoded + 4 > encoded_end) goto invalid_size;
407+
if (decoded + 4 * 4 * channels > decoded_end)
408+
goto invalid_size;
405409
Fill_IMA_ADPCM_block(decoded, encoded,
406410
c, channels, &state[c]);
407411
encoded += 4;

0 commit comments

Comments
 (0)