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