|
|
8d9706 |
From 8c46fe2fcf6ef4a74808f90711b3e9844632e8f7 Mon Sep 17 00:00:00 2001
|
|
|
8d9706 |
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
|
|
|
8d9706 |
Date: Mon, 10 Jun 2019 08:54:11 -0700
|
|
|
8d9706 |
Subject: [PATCH 04/11] CVE-2019-7577: Fix a buffer overread in MS_ADPCM_decode
|
|
|
8d9706 |
If RIFF/WAV data chunk length is shorter then expected for an audio format
|
|
|
8d9706 |
defined in preceeding RIFF/WAV format headers, a buffer overread can happen.
|
|
|
8d9706 |
MIME-Version: 1.0
|
|
|
8d9706 |
Content-Type: text/plain; charset=UTF-8
|
|
|
8d9706 |
Content-Transfer-Encoding: 8bit
|
|
|
8d9706 |
|
|
|
8d9706 |
This patch fixes it by checking a MS ADPCM data to be decoded are not
|
|
|
8d9706 |
past the initialized buffer.
|
|
|
8d9706 |
|
|
|
8d9706 |
CVE-2019-7577
|
|
|
8d9706 |
Reproducer: https://bugzilla.libsdl.org/show_bug.cgi?id=4492
|
|
|
8d9706 |
|
|
|
8d9706 |
Signed-off-by: Petr Písař <ppisar@redhat.com>
|
|
|
8d9706 |
|
|
|
8d9706 |
--HG--
|
|
|
8d9706 |
branch : SDL-1.2
|
|
|
8d9706 |
---
|
|
|
8d9706 |
src/audio/SDL_wave.c | 10 +++++++++-
|
|
|
8d9706 |
1 file changed, 9 insertions(+), 1 deletion(-)
|
|
|
8d9706 |
|
|
|
8d9706 |
diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c
|
|
|
8d9706 |
index 66f804421..6c6eb14eb 100644
|
|
|
8d9706 |
--- a/src/audio/SDL_wave.c
|
|
|
8d9706 |
+++ b/src/audio/SDL_wave.c
|
|
|
8d9706 |
@@ -115,7 +115,7 @@ static Sint32 MS_ADPCM_nibble(struct MS_ADPCM_decodestate *state,
|
|
|
8d9706 |
static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
|
|
|
8d9706 |
{
|
|
|
8d9706 |
struct MS_ADPCM_decodestate *state[2];
|
|
|
8d9706 |
- Uint8 *freeable, *encoded, *decoded;
|
|
|
8d9706 |
+ Uint8 *freeable, *encoded, *encoded_end, *decoded;
|
|
|
8d9706 |
Sint32 encoded_len, samplesleft;
|
|
|
8d9706 |
Sint8 nybble, stereo;
|
|
|
8d9706 |
Sint16 *coeff[2];
|
|
|
8d9706 |
@@ -124,6 +124,7 @@ static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
|
|
|
8d9706 |
/* Allocate the proper sized output buffer */
|
|
|
8d9706 |
encoded_len = *audio_len;
|
|
|
8d9706 |
encoded = *audio_buf;
|
|
|
8d9706 |
+ encoded_end = encoded + encoded_len;
|
|
|
8d9706 |
freeable = *audio_buf;
|
|
|
8d9706 |
*audio_len = (encoded_len/MS_ADPCM_state.wavefmt.blockalign) *
|
|
|
8d9706 |
MS_ADPCM_state.wSamplesPerBlock*
|
|
|
8d9706 |
@@ -141,6 +142,7 @@ static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
|
|
|
8d9706 |
state[1] = &MS_ADPCM_state.state[stereo];
|
|
|
8d9706 |
while ( encoded_len >= MS_ADPCM_state.wavefmt.blockalign ) {
|
|
|
8d9706 |
/* Grab the initial information for this block */
|
|
|
8d9706 |
+ if (encoded + 7 + (stereo ? 7 : 0) > encoded_end) goto too_short;
|
|
|
8d9706 |
state[0]->hPredictor = *encoded++;
|
|
|
8d9706 |
if ( stereo ) {
|
|
|
8d9706 |
state[1]->hPredictor = *encoded++;
|
|
|
8d9706 |
@@ -188,6 +190,8 @@ static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
|
|
|
8d9706 |
samplesleft = (MS_ADPCM_state.wSamplesPerBlock-2)*
|
|
|
8d9706 |
MS_ADPCM_state.wavefmt.channels;
|
|
|
8d9706 |
while ( samplesleft > 0 ) {
|
|
|
8d9706 |
+ if (encoded + 1 > encoded_end) goto too_short;
|
|
|
8d9706 |
+
|
|
|
8d9706 |
nybble = (*encoded)>>4;
|
|
|
8d9706 |
new_sample = MS_ADPCM_nibble(state[0],nybble,coeff[0]);
|
|
|
8d9706 |
decoded[0] = new_sample&0xFF;
|
|
|
8d9706 |
@@ -209,6 +213,10 @@ static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
|
|
|
8d9706 |
}
|
|
|
8d9706 |
SDL_free(freeable);
|
|
|
8d9706 |
return(0);
|
|
|
8d9706 |
+too_short:
|
|
|
8d9706 |
+ SDL_SetError("Too short chunk for a MS ADPCM decoder");
|
|
|
8d9706 |
+ SDL_free(freeable);
|
|
|
8d9706 |
+ return(-1);
|
|
|
8d9706 |
}
|
|
|
8d9706 |
|
|
|
8d9706 |
struct IMA_ADPCM_decodestate {
|
|
|
8d9706 |
--
|
|
|
8d9706 |
2.24.1
|
|
|
8d9706 |
|