Skip to content

Commit

Permalink
Merge pull request #3 from uploadcare/tiff-ifd-tests
Browse files Browse the repository at this point in the history
Tiff ifd tests
  • Loading branch information
wiredfool committed Sep 15, 2015
2 parents e4f9b69 + 0f87b1f commit b1066bd
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions PIL/IptcImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def getiptcinfo(im):
while app[offset:offset+4] == b"8BIM":
offset += 4
# resource code
code = JpegImagePlugin.i16(app, offset)
code = i16(app, offset)
offset += 2
# resource name (usually empty)
name_len = i8(app[offset])
Expand All @@ -226,7 +226,7 @@ def getiptcinfo(im):
if offset & 1:
offset += 1
# resource data block
size = JpegImagePlugin.i32(app, offset)
size = i32(app, offset)
offset += 4
if code == 0x0404:
# 0x0404 contains IPTC/NAA data
Expand Down
2 changes: 1 addition & 1 deletion PIL/JpegImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def _getexif(self):
# exif field 0x8825 is an offset pointer to the location
# of the nested embedded gps exif ifd.
# It should be a long, but may be corrupted.
file.seek(exif[0x8825])
file.seek(exif[0x8825])
except (KeyError, TypeError):
pass
else:
Expand Down
1 change: 0 additions & 1 deletion PIL/PixarImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
# helpers

i16 = _binary.i16le
i32 = _binary.i32le


##
Expand Down
1 change: 0 additions & 1 deletion PIL/SgiImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

i8 = _binary.i8
i16 = _binary.i16be
i32 = _binary.i32be


def _accept(prefix):
Expand Down
1 change: 0 additions & 1 deletion PIL/SunImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

__version__ = "0.3"

i16 = _binary.i16be
i32 = _binary.i32be


Expand Down
1 change: 0 additions & 1 deletion PIL/TgaImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

i8 = _binary.i8
i16 = _binary.i16le
i32 = _binary.i32le


MODES = {
Expand Down
3 changes: 2 additions & 1 deletion Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ def test_bad_mpo_header(self):

# Act
# Shouldn't raise error
im = Image.open("Tests/images/sugarshack_bad_mpo_header.jpg")
fn = "Tests/images/sugarshack_bad_mpo_header.jpg"
im = self.assert_warning(UserWarning, lambda: Image.open(fn))

# Assert
self.assertEqual(im.format, "JPEG")
Expand Down
3 changes: 2 additions & 1 deletion Tests/test_file_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ def test_invalid_file(self):
lambda: TiffImagePlugin.TiffImageFile(invalid_file))

def test_bad_exif(self):
i = Image.open('Tests/images/hopper_bad_exif.jpg')
try:
Image.open('Tests/images/hopper_bad_exif.jpg')._getexif()
self.assert_warning(UserWarning, lambda: i._getexif())
except struct.error:
self.fail(
"Bad EXIF data passed incorrect values to _binary unpack")
Expand Down
12 changes: 12 additions & 0 deletions Tests/test_file_tiff_metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import division

import io
import struct

from helper import unittest, PillowTestCase, hopper

from PIL import Image, TiffImagePlugin, TiffTags
Expand Down Expand Up @@ -136,6 +139,15 @@ def test_no_duplicate_50741_tag(self):
self.assertEqual(tag_ids['MakerNoteSafety'], 50741)
self.assertEqual(tag_ids['BestQualityScale'], 50780)

def test_empty_metadata(self):
f = io.BytesIO(b'II*\x00\x08\x00\x00\x00')
head = f.read(8)
info = TiffImagePlugin.ImageFileDirectory(head)
try:
self.assert_warning(UserWarning, lambda: info.load(f))
except struct.error:
self.fail("Should not be struct errors there.")


if __name__ == '__main__':
unittest.main()
Expand Down

0 comments on commit b1066bd

Please sign in to comment.