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

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