Skip to content

Commit

Permalink
Fix 6-byte OOB read in FliDecode
Browse files Browse the repository at this point in the history
  • Loading branch information
wiredfool authored and hugovk committed Sep 2, 2021
1 parent cece64f commit 94a0cf1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/libImaging/FliDecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,15 @@ ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt
break;
case 16:
/* COPY chunk */
if (state->xsize > bytes / state->ysize) {
if (INT32_MAX / state->xsize < state->ysize) {
/* Integer overflow, bail */
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
/* Note, have to check Data + size, not just ptr + size) */
if (data + (state->xsize * state->ysize) > ptr + bytes) {
/* not enough data for frame */
/* UNDONE Unclear that we're actually going to leave the buffer at the right place. */
return ptr - buf; /* bytes consumed */
}
for (y = 0; y < state->ysize; y++) {
Expand Down

0 comments on commit 94a0cf1

Please sign in to comment.