0ba851
From 4b4cac39ba7988df9d8def32360dd842b707ba74 Mon Sep 17 00:00:00 2001
0ba851
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
0ba851
Date: Sat, 8 Jun 2019 17:57:43 -0700
0ba851
Subject: [PATCH 01/11] CVE-2019-7572: Fix a buffer overread in
0ba851
 IMA_ADPCM_nibble If an IMA ADPCM block contained an initial index out of step
0ba851
 table range (loaded in IMA_ADPCM_decode()), IMA_ADPCM_nibble() blindly used
0ba851
 this bogus value and that lead to a buffer overread.
0ba851
MIME-Version: 1.0
0ba851
Content-Type: text/plain; charset=UTF-8
0ba851
Content-Transfer-Encoding: 8bit
0ba851
0ba851
This patch fixes it by moving clamping the index value at the
0ba851
beginning of IMA_ADPCM_nibble() function instead of the end after
0ba851
an update.
0ba851
0ba851
CVE-2019-7572
0ba851
https://bugzilla.libsdl.org/show_bug.cgi?id=4495
0ba851
0ba851
Signed-off-by: Petr Písař <ppisar@redhat.com>
0ba851
0ba851
--HG--
0ba851
branch : SDL-1.2
0ba851
---
0ba851
 src/audio/SDL_wave.c | 14 ++++++++------
0ba851
 1 file changed, 8 insertions(+), 6 deletions(-)
0ba851
0ba851
diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c
0ba851
index b4ad6c787..ba1fb5252 100644
0ba851
--- a/src/audio/SDL_wave.c
0ba851
+++ b/src/audio/SDL_wave.c
0ba851
@@ -264,6 +264,14 @@ static Sint32 IMA_ADPCM_nibble(struct IMA_ADPCM_decodestate *state,Uint8 nybble)
0ba851
 	};
0ba851
 	Sint32 delta, step;
0ba851
 
0ba851
+	/* Clamp index value. The inital value can be invalid. */
0ba851
+	if ( state->index > 88 ) {
0ba851
+		state->index = 88;
0ba851
+	} else
0ba851
+	if ( state->index < 0 ) {
0ba851
+		state->index = 0;
0ba851
+	}
0ba851
+
0ba851
 	/* Compute difference and new sample value */
0ba851
 	step = step_table[state->index];
0ba851
 	delta = step >> 3;
0ba851
@@ -275,12 +283,6 @@ static Sint32 IMA_ADPCM_nibble(struct IMA_ADPCM_decodestate *state,Uint8 nybble)
0ba851
 
0ba851
 	/* Update index value */
0ba851
 	state->index += index_table[nybble];
0ba851
-	if ( state->index > 88 ) {
0ba851
-		state->index = 88;
0ba851
-	} else
0ba851
-	if ( state->index < 0 ) {
0ba851
-		state->index = 0;
0ba851
-	}
0ba851
 
0ba851
 	/* Clamp output sample */
0ba851
 	if ( state->sample > max_audioval ) {
0ba851
-- 
0ba851
2.21.0
0ba851