Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions piexif/_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ def __init__(self, data):
raise InvalidImageDataError("Given file is neither JPEG nor TIFF.")

def get_ifd_dict(self, pointer, ifd_name, read_unknown=False):
try:
result = self._do_get_ifd_dict(pointer, ifd_name, read_unknown)
except struct.error:
# Bad pointers will appear as `struct.error`
result = {}
return result

def _do_get_ifd_dict(self, pointer, ifd_name, read_unknown=False):
ifd_dict = {}
tag_count = unpack_from(self.endian_mark + "H",
self.tiftag, pointer)[0]
Expand Down
Binary file added tests/images/r_bad_pointer.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion tests/s_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ def test_roundtrip_files(self):
if ifd == "0th":
if ImageIFD.ExifTag in exif["0th"]:
exif["0th"].pop(ImageIFD.ExifTag)
e["0th"].pop(ImageIFD.ExifTag)
# In case of invalid pointer, PIL uses
# pointer value as tag value, rather than skip it
e["0th"].pop(ImageIFD.ExifTag, None)
if ImageIFD.GPSTag in exif["0th"]:
exif["0th"].pop(ImageIFD.GPSTag)
e["0th"].pop(ImageIFD.GPSTag)
Expand Down