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

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