Blame SOURCES/0008-CVE-2019-7575-Fix-a-buffer-overwrite-in-MS_ADPCM_dec.patch

8d9706
From 5cf68a3fbb846da51e1b867e3fd92ec8d0e7a0dd Mon Sep 17 00:00:00 2001
8d9706
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
8d9706
Date: Mon, 10 Jun 2019 09:25:05 -0700
8d9706
Subject: [PATCH 08/11] CVE-2019-7575: Fix a buffer overwrite in
8d9706
 MS_ADPCM_decode If a WAV format defines shorter audio stream and decoded MS
8d9706
 ADPCM data chunk is longer, decoding continued past the output audio buffer.
8d9706
MIME-Version: 1.0
8d9706
Content-Type: text/plain; charset=UTF-8
8d9706
Content-Transfer-Encoding: 8bit
8d9706
8d9706
This fix is based on a patch from
8d9706
<https://bugzilla.libsdl.org/show_bug.cgi?id=4492>.
8d9706
8d9706
https://bugzilla.libsdl.org/show_bug.cgi?id=4493
8d9706
CVE-2019-7575
8d9706
8d9706
Signed-off-by: Petr Písař <ppisar@redhat.com>
8d9706
8d9706
--HG--
8d9706
branch : SDL-1.2
8d9706
---
8d9706
 src/audio/SDL_wave.c | 13 ++++++++-----
8d9706
 1 file changed, 8 insertions(+), 5 deletions(-)
8d9706
8d9706
diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c
8d9706
index 88ac2cca6..5f9365147 100644
8d9706
--- a/src/audio/SDL_wave.c
8d9706
+++ b/src/audio/SDL_wave.c
8d9706
@@ -122,7 +122,7 @@ static Sint32 MS_ADPCM_nibble(struct MS_ADPCM_decodestate *state,
8d9706
 static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
8d9706
 {
8d9706
 	struct MS_ADPCM_decodestate *state[2];
8d9706
-	Uint8 *freeable, *encoded, *encoded_end, *decoded;
8d9706
+	Uint8 *freeable, *encoded, *encoded_end, *decoded, *decoded_end;
8d9706
 	Sint32 encoded_len, samplesleft;
8d9706
 	Sint8 nybble, stereo;
8d9706
 	Sint16 *coeff[2];
8d9706
@@ -142,6 +142,7 @@ static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
8d9706
 		return(-1);
8d9706
 	}
8d9706
 	decoded = *audio_buf;
8d9706
+	decoded_end = decoded + *audio_len;
8d9706
 
8d9706
 	/* Get ready... Go! */
8d9706
 	stereo = (MS_ADPCM_state.wavefmt.channels == 2);
8d9706
@@ -149,7 +150,7 @@ static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
8d9706
 	state[1] = &MS_ADPCM_state.state[stereo];
8d9706
 	while ( encoded_len >= MS_ADPCM_state.wavefmt.blockalign ) {
8d9706
 		/* Grab the initial information for this block */
8d9706
-		if (encoded + 7 + (stereo ? 7 : 0) > encoded_end) goto too_short;
8d9706
+		if (encoded + 7 + (stereo ? 7 : 0) > encoded_end) goto invalid_size;
8d9706
 		state[0]->hPredictor = *encoded++;
8d9706
 		if ( stereo ) {
8d9706
 			state[1]->hPredictor = *encoded++;
8d9706
@@ -179,6 +180,7 @@ static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
8d9706
 		coeff[1] = MS_ADPCM_state.aCoeff[state[1]->hPredictor];
8d9706
 
8d9706
 		/* Store the two initial samples we start with */
8d9706
+		if (decoded + 4 + (stereo ? 4 : 0) > decoded_end) goto invalid_size;
8d9706
 		decoded[0] = state[0]->iSamp2&0xFF;
8d9706
 		decoded[1] = state[0]->iSamp2>>8;
8d9706
 		decoded += 2;
8d9706
@@ -200,7 +202,8 @@ static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
8d9706
 		samplesleft = (MS_ADPCM_state.wSamplesPerBlock-2)*
8d9706
 					MS_ADPCM_state.wavefmt.channels;
8d9706
 		while ( samplesleft > 0 ) {
8d9706
-			if (encoded + 1 > encoded_end) goto too_short;
8d9706
+			if (encoded + 1 > encoded_end) goto invalid_size;
8d9706
+			if (decoded + 4 > decoded_end) goto invalid_size;
8d9706
 
8d9706
 			nybble = (*encoded)>>4;
8d9706
 			new_sample = MS_ADPCM_nibble(state[0],nybble,coeff[0]);
8d9706
@@ -223,8 +226,8 @@ static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
8d9706
 	}
8d9706
 	SDL_free(freeable);
8d9706
 	return(0);
8d9706
-too_short:
8d9706
-	SDL_SetError("Too short chunk for a MS ADPCM decoder");
8d9706
+invalid_size:
8d9706
+	SDL_SetError("Unexpected chunk length for a MS ADPCM decoder");
8d9706
 	SDL_free(freeable);
8d9706
 	return(-1);
8d9706
 invalid_predictor:
8d9706
-- 
8d9706
2.24.1
8d9706