d05811d
From 9b2eee24768889378032077423cb6a3221a8ad18 Mon Sep 17 00:00:00 2001
d05811d
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
d05811d
Date: Thu, 14 Feb 2019 15:41:47 +0100
d05811d
Subject: [PATCH] CVE-2019-7574: Fix a buffer overread in IMA_ADPCM_decode
d05811d
MIME-Version: 1.0
d05811d
Content-Type: text/plain; charset=UTF-8
d05811d
Content-Transfer-Encoding: 8bit
d05811d
d05811d
If data chunk was shorter than expected based on a WAV format
d05811d
definition, IMA_ADPCM_decode() tried to read past the data chunk
d05811d
buffer. This patch fixes it.
d05811d
d05811d
CVE-2019-7574
d05811d
https://bugzilla.libsdl.org/show_bug.cgi?id=4496
d05811d
d05811d
Signed-off-by: Petr Písař <ppisar@redhat.com>
d05811d
---
d05811d
 src/audio/SDL_wave.c | 9 ++++++++-
d05811d
 1 file changed, 8 insertions(+), 1 deletion(-)
d05811d
d05811d
diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c
d05811d
index b6c49de..2968b3d 100644
d05811d
--- a/src/audio/SDL_wave.c
d05811d
+++ b/src/audio/SDL_wave.c
d05811d
@@ -334,7 +334,7 @@ static void Fill_IMA_ADPCM_block(Uint8 *decoded, Uint8 *encoded,
d05811d
 static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
d05811d
 {
d05811d
 	struct IMA_ADPCM_decodestate *state;
d05811d
-	Uint8 *freeable, *encoded, *decoded;
d05811d
+	Uint8 *freeable, *encoded, *encoded_end, *decoded;
d05811d
 	Sint32 encoded_len, samplesleft;
d05811d
 	unsigned int c, channels;
d05811d
 
d05811d
@@ -350,6 +350,7 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
d05811d
 	/* Allocate the proper sized output buffer */
d05811d
 	encoded_len = *audio_len;
d05811d
 	encoded = *audio_buf;
d05811d
+	encoded_end = encoded + encoded_len;
d05811d
 	freeable = *audio_buf;
d05811d
 	*audio_len = (encoded_len/IMA_ADPCM_state.wavefmt.blockalign) * 
d05811d
 				IMA_ADPCM_state.wSamplesPerBlock*
d05811d
@@ -365,6 +366,7 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
d05811d
 	while ( encoded_len >= IMA_ADPCM_state.wavefmt.blockalign ) {
d05811d
 		/* Grab the initial information for this block */
d05811d
 		for ( c=0; c
d05811d
+			if (encoded + 4 > encoded_end) goto invalid_size;
d05811d
 			/* Fill the state information for this block */
d05811d
 			state[c].sample = ((encoded[1]<<8)|encoded[0]);
d05811d
 			encoded += 2;
d05811d
@@ -387,6 +389,7 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
d05811d
 		samplesleft = (IMA_ADPCM_state.wSamplesPerBlock-1)*channels;
d05811d
 		while ( samplesleft > 0 ) {
d05811d
 			for ( c=0; c
d05811d
+				if (encoded + 4 > encoded_end) goto invalid_size;
d05811d
 				Fill_IMA_ADPCM_block(decoded, encoded,
d05811d
 						c, channels, &state[c]);
d05811d
 				encoded += 4;
d05811d
@@ -398,6 +401,10 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
d05811d
 	}
d05811d
 	SDL_free(freeable);
d05811d
 	return(0);
d05811d
+invalid_size:
d05811d
+	SDL_SetError("Unexpected chunk length for an IMA ADPCM decoder");
d05811d
+	SDL_free(freeable);
d05811d
+	return(-1);
d05811d
 }
d05811d
 
d05811d
 SDL_AudioSpec * SDL_LoadWAV_RW (SDL_RWops *src, int freesrc,
d05811d
-- 
d05811d
2.20.1
d05811d