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

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