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