Skip to content

Commit 94a0cf1

Browse files
wiredfoolhugovk
authored andcommitted
Fix 6-byte OOB read in FliDecode
1 parent cece64f commit 94a0cf1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/libImaging/FliDecode.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,15 @@ ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt
223223
break;
224224
case 16:
225225
/* COPY chunk */
226-
if (state->xsize > bytes / state->ysize) {
226+
if (INT32_MAX / state->xsize < state->ysize) {
227+
/* Integer overflow, bail */
228+
state->errcode = IMAGING_CODEC_OVERRUN;
229+
return -1;
230+
}
231+
/* Note, have to check Data + size, not just ptr + size) */
232+
if (data + (state->xsize * state->ysize) > ptr + bytes) {
227233
/* not enough data for frame */
234+
/* UNDONE Unclear that we're actually going to leave the buffer at the right place. */
228235
return ptr - buf; /* bytes consumed */
229236
}
230237
for (y = 0; y < state->ysize; y++) {

0 commit comments

Comments
 (0)