Skip to content

Commit

Permalink
Catch FLI buffer overrun
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jan 2, 2020
1 parent 774e53b commit a09acd0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Binary file added Tests/images/fli_overrun2.bin
Binary file not shown.
7 changes: 7 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,13 @@ def test_overrun(self):
except IOError as e:
self.assertEqual(str(e), "buffer overrun when reading image file")

with Image.open("Tests/images/fli_overrun2.bin") as im:
try:
im.seek(1)
self.assertFail()
except IOError as e:
self.assertEqual(str(e), "buffer overrun when reading image file")


class MockEncoder(object):
pass
Expand Down
7 changes: 5 additions & 2 deletions src/libImaging/FliDecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
return 0;

/* We don't decode anything unless we have a full chunk in the
input buffer (on the other hand, the Python part of the driver
makes sure this is always the case) */
input buffer */

ptr = buf;

Expand All @@ -52,6 +51,10 @@ ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
/* Make sure this is a frame chunk. The Python driver takes
case of other chunk types. */

if (bytes < 8) {
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
if (I16(ptr+4) != 0xF1FA) {
state->errcode = IMAGING_CODEC_UNKNOWN;
return -1;
Expand Down

2 comments on commit a09acd0

@NicoleG25
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that it appears that CVE-2020-5313 was assigned to this issue.

@hugovk
Copy link
Member

@hugovk hugovk commented on a09acd0 Jan 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.