Blame SOURCES/0006-CVE-2019-7572-Fix-a-buffer-overwrite-in-IMA_ADPCM_de.patch

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