Skip to content

Commit 1ead491

Browse files
committed
CVE-2019-7572: Fix a buffer overread in IMA_ADPCM_nibble
If an IMA ADPCM block contained an initial index out of step table range (loaded in IMA_ADPCM_decode()), IMA_ADPCM_nibble() blindly used this bogus value and that lead to a buffer overread. This patch fixes it by moving clamping the index value at the beginning of IMA_ADPCM_nibble() function instead of the end after an update. CVE-2019-7572 https://bugzilla.libsdl.org/show_bug.cgi?id=4495 Signed-off-by: Petr P?sa? <ppisar@redhat.com>
1 parent d8bd7c9 commit 1ead491

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/audio/SDL_wave.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,14 @@ static Sint32 IMA_ADPCM_nibble(struct IMA_ADPCM_decodestate *state,Uint8 nybble)
264264
};
265265
Sint32 delta, step;
266266

267+
/* Clamp index value. The inital value can be invalid. */
268+
if ( state->index > 88 ) {
269+
state->index = 88;
270+
} else
271+
if ( state->index < 0 ) {
272+
state->index = 0;
273+
}
274+
267275
/* Compute difference and new sample value */
268276
step = step_table[state->index];
269277
delta = step >> 3;
@@ -275,12 +283,6 @@ static Sint32 IMA_ADPCM_nibble(struct IMA_ADPCM_decodestate *state,Uint8 nybble)
275283

276284
/* Update index value */
277285
state->index += index_table[nybble];
278-
if ( state->index > 88 ) {
279-
state->index = 88;
280-
} else
281-
if ( state->index < 0 ) {
282-
state->index = 0;
283-
}
284286

285287
/* Clamp output sample */
286288
if ( state->sample > max_audioval ) {

0 commit comments

Comments
 (0)