  	freeable = *audio_buf;
  	*audio_len = (encoded_len/MS_ADPCM_state.wavefmt.blockalign) * 
  				MS_ADPCM_state.wSamplesPerBlock*
-@@ -141,6 +142,7 @@
+@@ -141,10 +142,14 @@ static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
  	state[1] = &MS_ADPCM_state.state[stereo];
  	while ( encoded_len >= MS_ADPCM_state.wavefmt.blockalign ) {
  		/* Grab the initial information for this block */
 +		if (encoded + 7 + (stereo ? 7 : 0) > encoded_end) goto too_short;
  		state[0]->hPredictor = *encoded++;
- 		if ( stereo ) {
- 			state[1]->hPredictor = *encoded++;
-@@ -188,6 +190,8 @@
- 		samplesleft = (MS_ADPCM_state.wSamplesPerBlock-2)*
- 					MS_ADPCM_state.wavefmt.channels;
- 		while ( samplesleft > 0 ) {
-+			if (encoded + 1 > encoded_end) goto too_short;
-+
- 			nybble = (*encoded)>>4;
- 			new_sample = MS_ADPCM_nibble(state[0],nybble,coeff[0]);
- 			decoded[0] = new_sample&0xFF;
-@@ -209,6 +213,10 @@
- 	}
- 	SDL_free(freeable);
- 	return(0);
-+too_short:
-+	SDL_SetError("Too short chunk for a MS ADPCM decoder");
-+	SDL_free(freeable);
-+	return(-1);
- }
- 
- struct IMA_ADPCM_decodestate {
-
-
-diff -r 416136310b88 -r faf9abbcfb5f src/audio/SDL_wave.c
---- a/src/audio/SDL_wave.c	Mon Jun 10 08:54:11 2019 -0700
-+++ b/src/audio/SDL_wave.c	Mon Jun 10 08:54:29 2019 -0700
-@@ -147,6 +147,9 @@
  		if ( stereo ) {
  			state[1]->hPredictor = *encoded++;
  		}

 	Sint32 encoded_len, samplesleft;
 	Sint8 nybble, stereo;
 	Sint16 *coeff[2];
@@ -124,6 +124,7 @@
 	/* Allocate the proper sized output buffer */
 	encoded_len = *audio_len;
 	encoded = *audio_buf;

 }
 
 struct IMA_ADPCM_decodestate {
-- 
2.7.4

