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

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