Skip to content
Open
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
20 changes: 13 additions & 7 deletions exifread/core/exif_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,19 +469,25 @@ def extract_jpeg_thumbnail(self) -> None:
thumb_offset = self.tags.get("Thumbnail JPEGInterchangeFormat")
thumb_length = self.tags.get("Thumbnail JPEGInterchangeFormatLength")
if thumb_offset and thumb_length:
self.file_handle.seek(self.offset + thumb_offset.values[0])
size = thumb_length.values[0]
self.tags["JPEGThumbnail"] = self.file_handle.read(size)
try:
self.file_handle.seek(self.offset + thumb_offset.values[0])
size = thumb_length.values[0]
self.tags["JPEGThumbnail"] = self.file_handle.read(size)
except TypeError:
logger.debug("Invalid JPEG thumbnail offset or length, skipping")

# Sometimes in a TIFF file, a JPEG thumbnail is hidden in the MakerNote
# since it's not allowed in a uncompressed TIFF IFD
if "JPEGThumbnail" not in self.tags:
thumb_offset = self.tags.get("MakerNote JPEGThumbnail")
if thumb_offset:
self.file_handle.seek(self.offset + thumb_offset.values[0])
self.tags["JPEGThumbnail"] = self.file_handle.read(
thumb_offset.field_length
)
try:
self.file_handle.seek(self.offset + thumb_offset.values[0])
self.tags["JPEGThumbnail"] = self.file_handle.read(
thumb_offset.field_length
)
except TypeError:
logger.debug("Invalid MakerNote thumbnail offset, skipping")

def decode_maker_note(self) -> None:
"""
Expand Down
8 changes: 7 additions & 1 deletion exifread/core/heic.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ def get_string(self) -> bytes:
def next_box(self) -> Box:
pos = self.file_handle.tell()
size = self.get32()
kind = self.get(4).decode("ascii")
raw = self.get(4)
try:
kind = raw.decode("ascii")
except UnicodeDecodeError:
raise InvalidExif(
"Invalid HEIC box type at offset %d: %r" % (pos, raw)
)
box = Box(kind)
if size == 0:
# signifies 'to the end of the file', we shouldn't see this.
Expand Down