Skip to content

Commit

Permalink
Allow for APP1 markers without EXIF data
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Mar 16, 2024
1 parent 794a7d6 commit d3ac789
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
12 changes: 12 additions & 0 deletions Tests/test_file_mpo.py
Expand Up @@ -91,6 +91,18 @@ def test_exif(test_file: str) -> None:
assert info[34665] == 188


def test_app1_not_exif() -> None:
with open("Tests/images/sugarshack.mpo", "rb") as fp:
data = fp.read()
data = data[:60014] + b" " + data[60015:]
b = BytesIO(data)
with Image.open(b) as im:
del im.info["exif"]

im.seek(1)
assert "exif" not in im.info


def test_frame_size() -> None:
# This image has been hexedited to contain a different size
# in the EXIF data of the second frame
Expand Down
18 changes: 10 additions & 8 deletions src/PIL/MpoImagePlugin.py
Expand Up @@ -145,14 +145,16 @@ def seek(self, frame):
self._size = self._initial_size
if i16(segment) == 0xFFE1: # APP1
n = i16(self.fp.read(2)) - 2
self.info["exif"] = ImageFile._safe_read(self.fp, n)
self._reload_exif()

mptype = self.mpinfo[0xB002][frame]["Attribute"]["MPType"]
if mptype.startswith("Large Thumbnail"):
exif = self.getexif().get_ifd(ExifTags.IFD.Exif)
if 40962 in exif and 40963 in exif:
self._size = (exif[40962], exif[40963])
s = ImageFile._safe_read(self.fp, n)
if s[:6] == b"Exif\0\0":
self.info["exif"] = s
self._reload_exif()

mptype = self.mpinfo[0xB002][frame]["Attribute"]["MPType"]
if mptype.startswith("Large Thumbnail"):
exif = self.getexif().get_ifd(ExifTags.IFD.Exif)
if 40962 in exif and 40963 in exif:
self._size = (exif[40962], exif[40963])
elif "exif" in self.info:
del self.info["exif"]
self._reload_exif()
Expand Down

0 comments on commit d3ac789

Please sign in to comment.