Blame SOURCES/0007-CVE-2019-7573-CVE-2019-7576-Fix-buffer-overreads-in-.patch

cfd472
From 45ef356d8c01a3941286b35b90eb319959f20f2c Mon Sep 17 00:00:00 2001
cfd472
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
cfd472
Date: Mon, 10 Jun 2019 09:06:23 -0700
cfd472
Subject: [PATCH 07/11] CVE-2019-7573, CVE-2019-7576: Fix buffer overreads in
cfd472
 InitMS_ADPCM If MS ADPCM format chunk was too short, InitMS_ADPCM() parsing
cfd472
 it could 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-7573
cfd472
https://bugzilla.libsdl.org/show_bug.cgi?id=4491
cfd472
CVE-2019-7576
cfd472
https://bugzilla.libsdl.org/show_bug.cgi?id=4490
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 | 13 ++++++++++---
cfd472
 1 file changed, 10 insertions(+), 3 deletions(-)
cfd472
cfd472
diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c
cfd472
index 4159eb710..88ac2cca6 100644
cfd472
--- a/src/audio/SDL_wave.c
cfd472
+++ b/src/audio/SDL_wave.c
cfd472
@@ -44,12 +44,13 @@ static struct MS_ADPCM_decoder {
cfd472
 	struct MS_ADPCM_decodestate state[2];
cfd472
 } MS_ADPCM_state;
cfd472
 
cfd472
-static int InitMS_ADPCM(WaveFMT *format)
cfd472
+static int InitMS_ADPCM(WaveFMT *format, int length)
cfd472
 {
cfd472
-	Uint8 *rogue_feel;
cfd472
+	Uint8 *rogue_feel, *rogue_feel_end;
cfd472
 	int i;
cfd472
 
cfd472
 	/* Set the rogue pointer to the MS_ADPCM specific data */
cfd472
+	if (length < sizeof(*format)) goto too_short;
cfd472
 	MS_ADPCM_state.wavefmt.encoding = SDL_SwapLE16(format->encoding);
cfd472
 	MS_ADPCM_state.wavefmt.channels = SDL_SwapLE16(format->channels);
cfd472
 	MS_ADPCM_state.wavefmt.frequency = SDL_SwapLE32(format->frequency);
cfd472
@@ -58,9 +59,11 @@ static int InitMS_ADPCM(WaveFMT *format)
cfd472
 	MS_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 + 4 > rogue_feel_end) goto too_short;
cfd472
 	MS_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1]<<8)|rogue_feel[0]);
cfd472
 	rogue_feel += sizeof(Uint16);
cfd472
 	MS_ADPCM_state.wNumCoef = ((rogue_feel[1]<<8)|rogue_feel[0]);
cfd472
@@ -70,12 +73,16 @@ static int InitMS_ADPCM(WaveFMT *format)
cfd472
 		return(-1);
cfd472
 	}
cfd472
 	for ( i=0; i
cfd472
+		if (rogue_feel + 4 > rogue_feel_end) goto too_short;
cfd472
 		MS_ADPCM_state.aCoeff[i][0] = ((rogue_feel[1]<<8)|rogue_feel[0]);
cfd472
 		rogue_feel += sizeof(Uint16);
cfd472
 		MS_ADPCM_state.aCoeff[i][1] = ((rogue_feel[1]<<8)|rogue_feel[0]);
cfd472
 		rogue_feel += sizeof(Uint16);
cfd472
 	}
cfd472
 	return(0);
cfd472
+too_short:
cfd472
+	SDL_SetError("Unexpected length of a chunk with a MS ADPCM format");
cfd472
+	return(-1);
cfd472
 }
cfd472
 
cfd472
 static Sint32 MS_ADPCM_nibble(struct MS_ADPCM_decodestate *state,
cfd472
@@ -495,7 +502,7 @@ SDL_AudioSpec * SDL_LoadWAV_RW (SDL_RWops *src, int freesrc,
cfd472
 			break;
cfd472
 		case MS_ADPCM_CODE:
cfd472
 			/* Try to understand this */
cfd472
-			if ( InitMS_ADPCM(format) < 0 ) {
cfd472
+			if ( InitMS_ADPCM(format, lenread) < 0 ) {
cfd472
 				was_error = 1;
cfd472
 				goto done;
cfd472
 			}
cfd472
-- 
cfd472
2.21.0
cfd472