Skip to content

Commit 6dcbf5b

Browse files
committed
Fix for buffer overflow in TiffDecode.c CVE-2016-0740
1 parent 5bdf54b commit 6dcbf5b

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

Tests/check_libtiff_segfault.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from helper import unittest, PillowTestCase
2+
from PIL import Image
3+
4+
TEST_FILE = "Tests/images/libtiff_segfault.tif"
5+
6+
class TestLibtiffSegfault(PillowTestCase):
7+
def test_segfault(self):
8+
""" This test should not segfault. It will on Pillow <= 3.1.0 and
9+
libtiff >= 4.0.0
10+
"""
11+
12+
try:
13+
im = Image.open(TEST_FILE)
14+
im.load()
15+
except IOError:
16+
self.assertTrue(True, "Got expected IOError")
17+
except Exception:
18+
self.fail("Should have returned IOError")
19+
20+
21+
22+
if __name__ == '__main__':
23+
unittest.main()

Tests/images/libtiff_segfault.tif

262 Bytes
Binary file not shown.

libImaging/TiffDecode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int
169169
char *filename = "tempfile.tif";
170170
char *mode = "r";
171171
TIFF *tiff;
172-
int size;
172+
tsize_t size;
173173

174174

175175
/* buffer is the encoded file, bytes is the length of the encoded file */

0 commit comments

Comments
 (0)