Blame SOURCES/0003-CVE-2019-7574-Fix-a-buffer-overread-in-IMA_ADPCM_dec.patch

cfd472
From db0282cbe00a64cc65ba445ea21928d72dc26d97 Mon Sep 17 00:00:00 2001
cfd472
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
cfd472
Date: Mon, 10 Jun 2019 08:50:59 -0700
cfd472
Subject: [PATCH 03/11] CVE-2019-7574: Fix a buffer overread in
cfd472
 IMA_ADPCM_decode If data chunk was shorter than expected based on a WAV
cfd472
 format definition, IMA_ADPCM_decode() tried to read past the data chunk
cfd472
 buffer. This patch fixes it.
cfd472
MIME-Version: 1.0
cfd472
Content-Type: text/plain; charset=UTF-8
cfd472
Content-Transfer-Encoding: 8bit
cfd472
cfd472
CVE-2019-7574
cfd472
https://bugzilla.libsdl.org/show_bug.cgi?id=4496
cfd472
cfd472
Signed-off-by: Petr Písař <ppisar@redhat.com>
cfd472
cfd472
--HG--
cfd472
branch : SDL-1.2
cfd472
---
cfd472
 src/audio/SDL_wave.c | 9 ++++++++-
cfd472
 1 file changed, 8 insertions(+), 1 deletion(-)
cfd472
cfd472
diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c
cfd472
index 21ee4dc3c..66f804421 100644
cfd472
--- a/src/audio/SDL_wave.c
cfd472
+++ b/src/audio/SDL_wave.c
cfd472
@@ -331,7 +331,7 @@ static void Fill_IMA_ADPCM_block(Uint8 *decoded, Uint8 *encoded,
cfd472
 static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
cfd472
 {
cfd472
 	struct IMA_ADPCM_decodestate *state;
cfd472
-	Uint8 *freeable, *encoded, *decoded;
cfd472
+	Uint8 *freeable, *encoded, *encoded_end, *decoded;
cfd472
 	Sint32 encoded_len, samplesleft;
cfd472
 	unsigned int c, channels;
cfd472
 
cfd472
@@ -347,6 +347,7 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
cfd472
 	/* Allocate the proper sized output buffer */
cfd472
 	encoded_len = *audio_len;
cfd472
 	encoded = *audio_buf;
cfd472
+	encoded_end = encoded + encoded_len;
cfd472
 	freeable = *audio_buf;
cfd472
 	*audio_len = (encoded_len/IMA_ADPCM_state.wavefmt.blockalign) * 
cfd472
 				IMA_ADPCM_state.wSamplesPerBlock*
cfd472
@@ -362,6 +363,7 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
cfd472
 	while ( encoded_len >= IMA_ADPCM_state.wavefmt.blockalign ) {
cfd472
 		/* Grab the initial information for this block */
cfd472
 		for ( c=0; c
cfd472
+			if (encoded + 4 > encoded_end) goto invalid_size;
cfd472
 			/* Fill the state information for this block */
cfd472
 			state[c].sample = ((encoded[1]<<8)|encoded[0]);
cfd472
 			encoded += 2;
cfd472
@@ -384,6 +386,7 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
cfd472
 		samplesleft = (IMA_ADPCM_state.wSamplesPerBlock-1)*channels;
cfd472
 		while ( samplesleft > 0 ) {
cfd472
 			for ( c=0; c
cfd472
+				if (encoded + 4 > encoded_end) goto invalid_size;
cfd472
 				Fill_IMA_ADPCM_block(decoded, encoded,
cfd472
 						c, channels, &state[c]);
cfd472
 				encoded += 4;
cfd472
@@ -395,6 +398,10 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
cfd472
 	}
cfd472
 	SDL_free(freeable);
cfd472
 	return(0);
cfd472
+invalid_size:
cfd472
+	SDL_SetError("Unexpected chunk length for an IMA ADPCM decoder");
cfd472
+	SDL_free(freeable);
cfd472
+	return(-1);
cfd472
 }
cfd472
 
cfd472
 SDL_AudioSpec * SDL_LoadWAV_RW (SDL_RWops *src, int freesrc,
cfd472
-- 
cfd472
2.21.0
cfd472