Skip to content

Commit

Permalink
Handle duplicate exif header
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
  • Loading branch information
radarhere committed Sep 6, 2024
1 parent 965cb51 commit fad5e54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,14 @@ def test_empty_exif(self) -> None:
exif.load(b"Exif\x00\x00")
assert not dict(exif)

def test_duplicate_exif_header(self) -> None:
with Image.open("Tests/images/exif.png") as im:
im.load()
im.info["exif"] = b"Exif\x00\x00" + im.info["exif"]

exif = im.getexif()
assert exif[274] == 1

def test_empty_get_ifd(self) -> None:
exif = Image.Exif()
ifd = exif.get_ifd(0x8769)
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3968,7 +3968,7 @@ def load(self, data: bytes) -> None:
self._data.clear()
self._hidden_data.clear()
self._ifds.clear()
if data and data.startswith(b"Exif\x00\x00"):
while data and data.startswith(b"Exif\x00\x00"):
data = data[6:]
if not data:
self._info = None
Expand Down

0 comments on commit fad5e54

Please sign in to comment.