7b383eb
From 3e2c89e516701f3586dfeadec13932f665371d2a Mon Sep 17 00:00:00 2001
7b383eb
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
7b383eb
Date: Fri, 15 Feb 2019 10:36:13 +0100
7b383eb
Subject: [PATCH] CVE-2019-7573, CVE-2019-7576: Fix buffer overreads in
7b383eb
 InitMS_ADPCM
7b383eb
MIME-Version: 1.0
7b383eb
Content-Type: text/plain; charset=UTF-8
7b383eb
Content-Transfer-Encoding: 8bit
7b383eb
7b383eb
If MS ADPCM format chunk was too short, InitMS_ADPCM() parsing it
7b383eb
could read past the end of chunk data. This patch fixes it.
7b383eb
7b383eb
CVE-2019-7573
7b383eb
https://bugzilla.libsdl.org/show_bug.cgi?id=4491
7b383eb
CVE-2019-7576
7b383eb
https://bugzilla.libsdl.org/show_bug.cgi?id=4490
7b383eb
7b383eb
Signed-off-by: Petr Písař <ppisar@redhat.com>
7b383eb
---
7b383eb
 src/audio/SDL_wave.c | 13 ++++++++++---
7b383eb
 1 file changed, 10 insertions(+), 3 deletions(-)
7b383eb
7b383eb
diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c
7b383eb
index 91e89e8..1d446ed 100644
7b383eb
--- a/src/audio/SDL_wave.c
7b383eb
+++ b/src/audio/SDL_wave.c
7b383eb
@@ -44,12 +44,13 @@ static struct MS_ADPCM_decoder {
7b383eb
 	struct MS_ADPCM_decodestate state[2];
7b383eb
 } MS_ADPCM_state;
7b383eb
 
7b383eb
-static int InitMS_ADPCM(WaveFMT *format)
7b383eb
+static int InitMS_ADPCM(WaveFMT *format, int length)
7b383eb
 {
7b383eb
-	Uint8 *rogue_feel;
7b383eb
+	Uint8 *rogue_feel, *rogue_feel_end;
7b383eb
 	int i;
7b383eb
 
7b383eb
 	/* Set the rogue pointer to the MS_ADPCM specific data */
7b383eb
+	if (length < sizeof(*format)) goto too_short;
7b383eb
 	MS_ADPCM_state.wavefmt.encoding = SDL_SwapLE16(format->encoding);
7b383eb
 	MS_ADPCM_state.wavefmt.channels = SDL_SwapLE16(format->channels);
7b383eb
 	MS_ADPCM_state.wavefmt.frequency = SDL_SwapLE32(format->frequency);
7b383eb
@@ -58,9 +59,11 @@ static int InitMS_ADPCM(WaveFMT *format)
7b383eb
 	MS_ADPCM_state.wavefmt.bitspersample =
7b383eb
 					 SDL_SwapLE16(format->bitspersample);
7b383eb
 	rogue_feel = (Uint8 *)format+sizeof(*format);
7b383eb
+	rogue_feel_end = (Uint8 *)format + length;
7b383eb
 	if ( sizeof(*format) == 16 ) {
7b383eb
 		rogue_feel += sizeof(Uint16);
7b383eb
 	}
7b383eb
+	if (rogue_feel + 4 > rogue_feel_end) goto too_short;
7b383eb
 	MS_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1]<<8)|rogue_feel[0]);
7b383eb
 	rogue_feel += sizeof(Uint16);
7b383eb
 	MS_ADPCM_state.wNumCoef = ((rogue_feel[1]<<8)|rogue_feel[0]);
7b383eb
@@ -70,12 +73,16 @@ static int InitMS_ADPCM(WaveFMT *format)
7b383eb
 		return(-1);
7b383eb
 	}
7b383eb
 	for ( i=0; i
7b383eb
+		if (rogue_feel + 4 > rogue_feel_end) goto too_short;
7b383eb
 		MS_ADPCM_state.aCoeff[i][0] = ((rogue_feel[1]<<8)|rogue_feel[0]);
7b383eb
 		rogue_feel += sizeof(Uint16);
7b383eb
 		MS_ADPCM_state.aCoeff[i][1] = ((rogue_feel[1]<<8)|rogue_feel[0]);
7b383eb
 		rogue_feel += sizeof(Uint16);
7b383eb
 	}
7b383eb
 	return(0);
7b383eb
+too_short:
7b383eb
+	SDL_SetError("Unexpected length of a chunk with a MS ADPCM format");
7b383eb
+	return(-1);
7b383eb
 }
7b383eb
 
7b383eb
 static Sint32 MS_ADPCM_nibble(struct MS_ADPCM_decodestate *state,
7b383eb
@@ -485,7 +492,7 @@ SDL_AudioSpec * SDL_LoadWAV_RW (SDL_RWops *src, int freesrc,
7b383eb
 			break;
7b383eb
 		case MS_ADPCM_CODE:
7b383eb
 			/* Try to understand this */
7b383eb
-			if ( InitMS_ADPCM(format) < 0 ) {
7b383eb
+			if ( InitMS_ADPCM(format, lenread) < 0 ) {
7b383eb
 				was_error = 1;
7b383eb
 				goto done;
7b383eb
 			}
7b383eb
-- 
7b383eb
2.20.1
7b383eb