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

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