CVE-2019-7577: Fix a buffer overread in MS_ADPCM_nibble and MS_ADPCM_decode SDL-1.2
authorPetr Písař <ppisar@redhat.com>
Mon, 10 Jun 2019 08:54:29 -0700
branchSDL-1.2
changeset 12817faf9abbcfb5f
parent 12816 416136310b88
child 12818 a8afedbcaea0
CVE-2019-7577: Fix a buffer overread in MS_ADPCM_nibble and MS_ADPCM_decode
If a chunk of RIFF/WAV file with MS ADPCM encoding contains an invalid
predictor (a valid predictor's value is between 0 and 6 inclusive),
a buffer overread can happen when the predictor is used as an index
into an array of MS ADPCM coefficients.

The overead happens when indexing MS_ADPCM_state.aCoeff[] array in
MS_ADPCM_decode() and later when dereferencing a coef pointer in
MS_ADPCM_nibble().

This patch fixes it by checking the MS ADPCM predictor values fit
into the valid range.

CVE-2019-7577
Reproducer: https://bugzilla.libsdl.org/show_bug.cgi?id=4492

Signed-off-by: Petr Písař <ppisar@redhat.com>
src/audio/SDL_wave.c
     1.1 --- a/src/audio/SDL_wave.c	Mon Jun 10 08:54:11 2019 -0700
     1.2 +++ b/src/audio/SDL_wave.c	Mon Jun 10 08:54:29 2019 -0700
     1.3 @@ -147,6 +147,9 @@
     1.4  		if ( stereo ) {
     1.5  			state[1]->hPredictor = *encoded++;
     1.6  		}
     1.7 +		if (state[0]->hPredictor >= 7 || state[1]->hPredictor >= 7) {
     1.8 +			goto invalid_predictor;
     1.9 +		}
    1.10  		state[0]->iDelta = ((encoded[1]<<8)|encoded[0]);
    1.11  		encoded += sizeof(Sint16);
    1.12  		if ( stereo ) {
    1.13 @@ -217,6 +220,10 @@
    1.14  	SDL_SetError("Too short chunk for a MS ADPCM decoder");
    1.15  	SDL_free(freeable);
    1.16  	return(-1);
    1.17 +invalid_predictor:
    1.18 +	SDL_SetError("Invalid predictor value for a MS ADPCM decoder");
    1.19 +	SDL_free(freeable);
    1.20 +	return(-1);
    1.21  }
    1.22  
    1.23  struct IMA_ADPCM_decodestate {