Blame SOURCES/0004-CVE-2019-7577-Fix-a-buffer-overread-in-MS_ADPCM_deco.patch

cfd472
From d5ec943db7d51fccd7230c9df0c7a2e46d611f50 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:11 -0700
cfd472
Subject: [PATCH 04/11] CVE-2019-7577: Fix a buffer overread in MS_ADPCM_decode
cfd472
 If RIFF/WAV data chunk length is shorter then expected for an audio format
cfd472
 defined in preceeding RIFF/WAV format headers, a buffer overread can happen.
cfd472
MIME-Version: 1.0
cfd472
Content-Type: text/plain; charset=UTF-8
cfd472
Content-Transfer-Encoding: 8bit
cfd472
cfd472
This patch fixes it by checking a MS ADPCM data to be decoded are not
cfd472
past the initialized buffer.
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 | 10 +++++++++-
cfd472
 1 file changed, 9 insertions(+), 1 deletion(-)
cfd472
cfd472
diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c
cfd472
index 66f804421..6c6eb14eb 100644
cfd472
--- a/src/audio/SDL_wave.c
cfd472
+++ b/src/audio/SDL_wave.c
cfd472
@@ -115,7 +115,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, *decoded;
cfd472
+	Uint8 *freeable, *encoded, *encoded_end, *decoded;
cfd472
 	Sint32 encoded_len, samplesleft;
cfd472
 	Sint8 nybble, stereo;
cfd472
 	Sint16 *coeff[2];
cfd472
@@ -124,6 +124,7 @@ static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
cfd472
 	/* Allocate the proper sized output buffer */
cfd472
 	encoded_len = *audio_len;
cfd472
 	encoded = *audio_buf;
cfd472
+	encoded_end = encoded + encoded_len;
cfd472
 	freeable = *audio_buf;
cfd472
 	*audio_len = (encoded_len/MS_ADPCM_state.wavefmt.blockalign) * 
cfd472
 				MS_ADPCM_state.wSamplesPerBlock*
cfd472
@@ -141,6 +142,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
 		state[0]->hPredictor = *encoded++;
cfd472
 		if ( stereo ) {
cfd472
 			state[1]->hPredictor = *encoded++;
cfd472
@@ -188,6 +190,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
+
cfd472
 			nybble = (*encoded)>>4;
cfd472
 			new_sample = MS_ADPCM_nibble(state[0],nybble,coeff[0]);
cfd472
 			decoded[0] = new_sample&0xFF;
cfd472
@@ -209,6 +213,10 @@ 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
+	SDL_free(freeable);
cfd472
+	return(-1);
cfd472
 }
cfd472
 
cfd472
 struct IMA_ADPCM_decodestate {
cfd472
-- 
cfd472
2.21.0
cfd472