a19bfa
From 3e53d4b122df0aeb5cbc27622614f9a72d8c2564 Mon Sep 17 00:00:00 2001
a19bfa
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
a19bfa
Date: Mon, 10 Jun 2019 08:57:11 -0700
a19bfa
Subject: [PATCH 06/11] CVE-2019-7572: Fix a buffer overwrite in
a19bfa
 IMA_ADPCM_decode If data chunk was longer than expected based on a WAV format
a19bfa
 definition, IMA_ADPCM_decode() tried to write past the output buffer. This
a19bfa
 patch fixes it.
a19bfa
MIME-Version: 1.0
a19bfa
Content-Type: text/plain; charset=UTF-8
a19bfa
Content-Transfer-Encoding: 8bit
a19bfa
a19bfa
Based on patch from
a19bfa
<https://bugzilla.libsdl.org/show_bug.cgi?id=4496>.
a19bfa
a19bfa
CVE-2019-7572
a19bfa
https://bugzilla.libsdl.org/show_bug.cgi?id=4495
a19bfa
a19bfa
Signed-off-by: Petr Písař <ppisar@redhat.com>
a19bfa
a19bfa
--HG--
a19bfa
branch : SDL-1.2
a19bfa
---
a19bfa
 src/audio/SDL_wave.c | 6 +++++-
a19bfa
 1 file changed, 5 insertions(+), 1 deletion(-)
a19bfa
a19bfa
diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c
a19bfa
index 3eedd20a1..4159eb710 100644
a19bfa
--- a/src/audio/SDL_wave.c
a19bfa
+++ b/src/audio/SDL_wave.c
a19bfa
@@ -346,7 +346,7 @@ static void Fill_IMA_ADPCM_block(Uint8 *decoded, Uint8 *encoded,
a19bfa
 static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
a19bfa
 {
a19bfa
 	struct IMA_ADPCM_decodestate *state;
a19bfa
-	Uint8 *freeable, *encoded, *encoded_end, *decoded;
a19bfa
+	Uint8 *freeable, *encoded, *encoded_end, *decoded, *decoded_end;
a19bfa
 	Sint32 encoded_len, samplesleft;
a19bfa
 	unsigned int c, channels;
a19bfa
 
a19bfa
@@ -373,6 +373,7 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
a19bfa
 		return(-1);
a19bfa
 	}
a19bfa
 	decoded = *audio_buf;
a19bfa
+	decoded_end = decoded + *audio_len;
a19bfa
 
a19bfa
 	/* Get ready... Go! */
a19bfa
 	while ( encoded_len >= IMA_ADPCM_state.wavefmt.blockalign ) {
a19bfa
@@ -392,6 +393,7 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
a19bfa
 			}
a19bfa
 
a19bfa
 			/* Store the initial sample we start with */
a19bfa
+			if (decoded + 2 > decoded_end) goto invalid_size;
a19bfa
 			decoded[0] = (Uint8)(state[c].sample&0xFF);
a19bfa
 			decoded[1] = (Uint8)(state[c].sample>>8);
a19bfa
 			decoded += 2;
a19bfa
@@ -402,6 +404,8 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
a19bfa
 		while ( samplesleft > 0 ) {
a19bfa
 			for ( c=0; c
a19bfa
 				if (encoded + 4 > encoded_end) goto invalid_size;
a19bfa
+				if (decoded + 4 * 4 * channels > decoded_end)
a19bfa
+					goto invalid_size;
a19bfa
 				Fill_IMA_ADPCM_block(decoded, encoded,
a19bfa
 						c, channels, &state[c]);
a19bfa
 				encoded += 4;
a19bfa
-- 
a19bfa
2.24.1
a19bfa