6ed69d
From 06d20617d0d5bb89a6caf5f2201c93baf03c43c2 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:54:29 -0700
6ed69d
Subject: [PATCH 05/11] CVE-2019-7577: Fix a buffer overread in MS_ADPCM_nibble
6ed69d
 and MS_ADPCM_decode If a chunk of RIFF/WAV file with MS ADPCM encoding
6ed69d
 contains an invalid predictor (a valid predictor's value is between 0 and 6
6ed69d
 inclusive), a buffer overread can happen when the predictor is used as an
6ed69d
 index into an array of MS ADPCM coefficients.
6ed69d
MIME-Version: 1.0
6ed69d
Content-Type: text/plain; charset=UTF-8
6ed69d
Content-Transfer-Encoding: 8bit
6ed69d
6ed69d
The overead happens when indexing MS_ADPCM_state.aCoeff[] array in
6ed69d
MS_ADPCM_decode() and later when dereferencing a coef pointer in
6ed69d
MS_ADPCM_nibble().
6ed69d
6ed69d
This patch fixes it by checking the MS ADPCM predictor values fit
6ed69d
into the valid range.
6ed69d
6ed69d
CVE-2019-7577
6ed69d
Reproducer: https://bugzilla.libsdl.org/show_bug.cgi?id=4492
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 | 7 +++++++
6ed69d
 1 file changed, 7 insertions(+)
6ed69d
6ed69d
diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c
6ed69d
index 6c6eb14eb..3eedd20a1 100644
6ed69d
--- a/src/audio/SDL_wave.c
6ed69d
+++ b/src/audio/SDL_wave.c
6ed69d
@@ -147,6 +147,9 @@ static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
6ed69d
 		if ( stereo ) {
6ed69d
 			state[1]->hPredictor = *encoded++;
6ed69d
 		}
6ed69d
+		if (state[0]->hPredictor >= 7 || state[1]->hPredictor >= 7) {
6ed69d
+			goto invalid_predictor;
6ed69d
+		}
6ed69d
 		state[0]->iDelta = ((encoded[1]<<8)|encoded[0]);
6ed69d
 		encoded += sizeof(Sint16);
6ed69d
 		if ( stereo ) {
6ed69d
@@ -217,6 +220,10 @@ too_short:
6ed69d
 	SDL_SetError("Too short chunk for a MS ADPCM decoder");
6ed69d
 	SDL_free(freeable);
6ed69d
 	return(-1);
6ed69d
+invalid_predictor:
6ed69d
+	SDL_SetError("Invalid predictor value for a MS ADPCM decoder");
6ed69d
+	SDL_free(freeable);
6ed69d
+	return(-1);
6ed69d
 }
6ed69d
 
6ed69d
 struct IMA_ADPCM_decodestate {
6ed69d
-- 
6ed69d
2.21.0
6ed69d