Compare commits

...

3 Commits
main ... 2.8.x

Author SHA1 Message Date
Alex Clark
0222a059d6 Prep 2.8.2 2015-06-06 19:52:13 -04:00
Andrew Murray
b6078a0d64 Added test for bad EXIF data 2015-06-06 19:46:36 -04:00
Andrew Murray
733dda7b4e Fixed Tiff handling of bad EXIF data 2015-06-06 19:46:19 -04:00
7 changed files with 30 additions and 4 deletions

View File

@ -1,6 +1,12 @@
Changelog (Pillow) Changelog (Pillow)
================== ==================
2.8.2 (2015-06-06)
------------------
- Bug fix: Fixed Tiff handling of bad EXIF data
[radarhere]
2.8.1 (2015-04-02) 2.8.1 (2015-04-02)
------------------ ------------------

View File

@ -426,6 +426,11 @@ class ImageFileDirectory(collections.MutableMapping):
for i in range(i16(fp.read(2))): for i in range(i16(fp.read(2))):
ifd = fp.read(12) ifd = fp.read(12)
if len(ifd) != 12:
warnings.warn("Possibly corrupt EXIF data. "
"Expecting to read 12 bytes but only got %d."
% (len(ifd)))
continue
tag, typ = i16(ifd), i16(ifd, 2) tag, typ = i16(ifd), i16(ifd, 2)
@ -476,7 +481,14 @@ class ImageFileDirectory(collections.MutableMapping):
else: else:
print("- value:", self[tag]) print("- value:", self[tag])
self.next = i32(fp.read(4)) ifd = fp.read(4)
if len(ifd) != 4:
warnings.warn("Possibly corrupt EXIF data. "
"Expecting to read 4 bytes but only got %d."
% (len(ifd)))
return
self.next = i32(ifd)
# save primitives # save primitives

View File

@ -12,7 +12,7 @@
# ;-) # ;-)
VERSION = '1.1.7' # PIL version VERSION = '1.1.7' # PIL version
PILLOW_VERSION = '2.8.1' # Pillow PILLOW_VERSION = '2.8.2' # Pillow
_plugins = ['BmpImagePlugin', _plugins = ['BmpImagePlugin',
'BufrStubImagePlugin', 'BufrStubImagePlugin',

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

View File

@ -2,6 +2,8 @@ from helper import unittest, PillowTestCase, hopper, py3
from PIL import Image, TiffImagePlugin from PIL import Image, TiffImagePlugin
import struct
class TestFileTiff(PillowTestCase): class TestFileTiff(PillowTestCase):
@ -76,6 +78,12 @@ class TestFileTiff(PillowTestCase):
im._setup() im._setup()
self.assertEqual(im.info['dpi'], (72., 72.)) self.assertEqual(im.info['dpi'], (72., 72.))
def test_bad_exif(self):
try:
Image.open('Tests/images/hopper_bad_exif.jpg')._getexif()
except struct.error:
self.fail("Bad EXIF data should not pass incorrect values to _binary unpack")
def test_little_endian(self): def test_little_endian(self):
im = Image.open('Tests/images/16bit.cropped.tif') im = Image.open('Tests/images/16bit.cropped.tif')
self.assertEqual(im.getpixel((0, 0)), 480) self.assertEqual(im.getpixel((0, 0)), 480)

View File

@ -71,7 +71,7 @@
* See the README file for information on usage and redistribution. * See the README file for information on usage and redistribution.
*/ */
#define PILLOW_VERSION "2.8.1" #define PILLOW_VERSION "2.8.2"
#include "Python.h" #include "Python.h"

View File

@ -90,7 +90,7 @@ except (ImportError, OSError):
NAME = 'Pillow' NAME = 'Pillow'
PILLOW_VERSION = '2.8.1' PILLOW_VERSION = '2.8.2'
TCL_ROOT = None TCL_ROOT = None
JPEG_ROOT = None JPEG_ROOT = None
JPEG2K_ROOT = None JPEG2K_ROOT = None