@@ -229,25 +229,30 @@ static struct IMA_ADPCM_decoder
229
229
} IMA_ADPCM_state ;
230
230
231
231
static int
232
- InitIMA_ADPCM (WaveFMT * format )
232
+ InitIMA_ADPCM (WaveFMT * format , int length )
233
233
{
234
- Uint8 * rogue_feel ;
234
+ Uint8 * rogue_feel , * rogue_feel_end ;
235
235
236
236
/* Set the rogue pointer to the IMA_ADPCM specific data */
237
+ if (length < sizeof (* format )) goto too_short ;
237
238
IMA_ADPCM_state .wavefmt .encoding = SDL_SwapLE16 (format -> encoding );
238
239
IMA_ADPCM_state .wavefmt .channels = SDL_SwapLE16 (format -> channels );
239
240
IMA_ADPCM_state .wavefmt .frequency = SDL_SwapLE32 (format -> frequency );
240
241
IMA_ADPCM_state .wavefmt .byterate = SDL_SwapLE32 (format -> byterate );
241
242
IMA_ADPCM_state .wavefmt .blockalign = SDL_SwapLE16 (format -> blockalign );
242
- IMA_ADPCM_state .wavefmt .bitspersample =
243
- SDL_SwapLE16 (format -> bitspersample );
243
+ IMA_ADPCM_state .wavefmt .bitspersample = SDL_SwapLE16 (format -> bitspersample );
244
244
rogue_feel = (Uint8 * ) format + sizeof (* format );
245
+ rogue_feel_end = (Uint8 * ) format + length ;
245
246
if (sizeof (* format ) == 16 ) {
246
247
/* const Uint16 extra_info = ((rogue_feel[1] << 8) | rogue_feel[0]); */
247
248
rogue_feel += sizeof (Uint16 );
248
249
}
250
+ if (rogue_feel + 2 > rogue_feel_end ) goto too_short ;
249
251
IMA_ADPCM_state .wSamplesPerBlock = ((rogue_feel [1 ] << 8 ) | rogue_feel [0 ]);
250
252
return (0 );
253
+ too_short :
254
+ SDL_SetError ("Unexpected length of a chunk with an IMA ADPCM format" );
255
+ return (-1 );
251
256
}
252
257
253
258
static Sint32
@@ -530,7 +535,7 @@ SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
530
535
break ;
531
536
case IMA_ADPCM_CODE :
532
537
/* Try to understand this */
533
- if (InitIMA_ADPCM (format ) < 0 ) {
538
+ if (InitIMA_ADPCM (format , lenread ) < 0 ) {
534
539
was_error = 1 ;
535
540
goto done ;
536
541
}
0 commit comments