Skip to content

Commit

Permalink
Seek to IFD offset
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jan 15, 2019
1 parent 8e4d547 commit 0481d0a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
Binary file added Tests/images/exif-ifd-offset.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/sugarshack_ifd_offset.mpo
Binary file not shown.
9 changes: 9 additions & 0 deletions Tests/test_file_jpeg.py
Expand Up @@ -581,6 +581,15 @@ def test_invalid_exif(self):
# OSError for unidentified image.
self.assertEqual(im.info.get("dpi"), (72, 72))

def test_ifd_offset_exif(self):
# Arrange
# This image has been manually hexedited to have an IFD offset of 10,
# in contrast to normal 8
im = Image.open("Tests/images/exif-ifd-offset.jpg")

# Act / Assert
self.assertEqual(im._getexif()[306], '2017:03:13 23:03:09')


@unittest.skipUnless(sys.platform.startswith('win32'), "Windows only")
class TestFileCloseW32(PillowTestCase):
Expand Down
8 changes: 8 additions & 0 deletions Tests/test_file_mpo.py
Expand Up @@ -62,6 +62,14 @@ def test_mp(self):
self.assertEqual(mpinfo[45056], b'0100')
self.assertEqual(mpinfo[45057], 2)

def test_mp_offset(self):
# This image has been manually hexedited to have an IFD offset of 10
# in APP2 data, in contrast to normal 8
im = Image.open("Tests/images/sugarshack_ifd_offset.mpo")
mpinfo = im._getmp()
self.assertEqual(mpinfo[45056], b'0100')
self.assertEqual(mpinfo[45057], 2)

def test_mp_attribute(self):
for test_file in test_files:
im = Image.open(test_file)
Expand Down
2 changes: 2 additions & 0 deletions src/PIL/JpegImagePlugin.py
Expand Up @@ -463,6 +463,7 @@ def _getexif(self):
head = file.read(8)
# process dictionary
info = TiffImagePlugin.ImageFileDirectory_v1(head)
file.seek(info.next)
info.load(file)
exif = dict(_fixup_dict(info))
# get exif extension
Expand Down Expand Up @@ -510,6 +511,7 @@ def _getmp(self):
# process dictionary
try:
info = TiffImagePlugin.ImageFileDirectory_v2(head)
file_contents.seek(info.next)
info.load(file_contents)
mp = dict(info)
except Exception:
Expand Down

0 comments on commit 0481d0a

Please sign in to comment.