Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Handle images that has corrupted headers/tags (#152)
Signed-off-by: Harmouch101 <mahmoudddharmouchhh@gmail.com>
  • Loading branch information
wiseaidev committed Feb 17, 2022
1 parent 11600ec commit 151d806
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions exifread/classes.py
Expand Up @@ -169,7 +169,12 @@ def _process_field(self, tag_name, count, field_type, type_length, offset):
unpack_format += 'd'
self.file_handle.seek(self.offset + offset)
byte_str = self.file_handle.read(type_length)
value = struct.unpack(unpack_format, byte_str)
try:
value = struct.unpack(unpack_format, byte_str)
except struct.error:
logger.warning('Possibly corrupted field %s', tag_name)
# -1 means corrupted
value = -1
else:
value = self.s2n(offset, type_length, signed)
values.append(value)
Expand Down Expand Up @@ -247,7 +252,6 @@ def _process_tag(self, ifd, ifd_name: str, tag_entry, entry, tag: int, tag_name,
values = self._process_field2(ifd_name, tag_name, count, offset)
else:
values = self._process_field(tag_name, count, field_type, type_length, offset)

# now 'values' is either a string or an array
# TODO: use only one type
if count == 1 and field_type != 2:
Expand Down

0 comments on commit 151d806

Please sign in to comment.