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

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