Blame SOURCES/0002-CVE-2019-7578-Fix-a-buffer-overread-in-InitIMA_ADPCM.patch

cfd472
From 210e68f70a5a007b0664239aa557e6b9d1b3e830 Mon Sep 17 00:00:00 2001
cfd472
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
cfd472
Date: Sat, 8 Jun 2019 18:02:09 -0700
cfd472
Subject: [PATCH 02/11] CVE-2019-7578: Fix a buffer overread in InitIMA_ADPCM
cfd472
 If IMA ADPCM format chunk was too short, InitIMA_ADPCM() parsing it could
cfd472
 read past the end of chunk data. This patch fixes it.
cfd472
MIME-Version: 1.0
cfd472
Content-Type: text/plain; charset=UTF-8
cfd472
Content-Transfer-Encoding: 8bit
cfd472
cfd472
CVE-2019-7578
cfd472
https://bugzilla.libsdl.org/show_bug.cgi?id=4494
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 | 12 +++++++++---
cfd472
 1 file changed, 9 insertions(+), 3 deletions(-)
cfd472
cfd472
diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c
cfd472
index ba1fb5252..21ee4dc3c 100644
cfd472
--- a/src/audio/SDL_wave.c
cfd472
+++ b/src/audio/SDL_wave.c
cfd472
@@ -222,11 +222,12 @@ static struct IMA_ADPCM_decoder {
cfd472
 	struct IMA_ADPCM_decodestate state[2];
cfd472
 } IMA_ADPCM_state;
cfd472
 
cfd472
-static int InitIMA_ADPCM(WaveFMT *format)
cfd472
+static int InitIMA_ADPCM(WaveFMT *format, int length)
cfd472
 {
cfd472
-	Uint8 *rogue_feel;
cfd472
+	Uint8 *rogue_feel, *rogue_feel_end;
cfd472
 
cfd472
 	/* Set the rogue pointer to the IMA_ADPCM specific data */
cfd472
+	if (length < sizeof(*format)) goto too_short;
cfd472
 	IMA_ADPCM_state.wavefmt.encoding = SDL_SwapLE16(format->encoding);
cfd472
 	IMA_ADPCM_state.wavefmt.channels = SDL_SwapLE16(format->channels);
cfd472
 	IMA_ADPCM_state.wavefmt.frequency = SDL_SwapLE32(format->frequency);
cfd472
@@ -235,11 +236,16 @@ static int InitIMA_ADPCM(WaveFMT *format)
cfd472
 	IMA_ADPCM_state.wavefmt.bitspersample =
cfd472
 					 SDL_SwapLE16(format->bitspersample);
cfd472
 	rogue_feel = (Uint8 *)format+sizeof(*format);
cfd472
+	rogue_feel_end = (Uint8 *)format + length;
cfd472
 	if ( sizeof(*format) == 16 ) {
cfd472
 		rogue_feel += sizeof(Uint16);
cfd472
 	}
cfd472
+	if (rogue_feel + 2 > rogue_feel_end) goto too_short;
cfd472
 	IMA_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1]<<8)|rogue_feel[0]);
cfd472
 	return(0);
cfd472
+too_short:
cfd472
+	SDL_SetError("Unexpected length of a chunk with an IMA ADPCM format");
cfd472
+	return(-1);
cfd472
 }
cfd472
 
cfd472
 static Sint32 IMA_ADPCM_nibble(struct IMA_ADPCM_decodestate *state,Uint8 nybble)
cfd472
@@ -471,7 +477,7 @@ SDL_AudioSpec * SDL_LoadWAV_RW (SDL_RWops *src, int freesrc,
cfd472
 			break;
cfd472
 		case IMA_ADPCM_CODE:
cfd472
 			/* Try to understand this */
cfd472
-			if ( InitIMA_ADPCM(format) < 0 ) {
cfd472
+			if ( InitIMA_ADPCM(format, lenread) < 0 ) {
cfd472
 				was_error = 1;
cfd472
 				goto done;
cfd472
 			}
cfd472
-- 
cfd472
2.21.0
cfd472