From 0cc2e696cb4ad46201e34e3b5694226fbd7c6294 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 7 Jun 2020 20:01:04 +1000 Subject: [PATCH] Corrected reading EXIF metadata without prefix --- Tests/test_file_webp_metadata.py | 9 +++++++++ src/PIL/Image.py | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_webp_metadata.py b/Tests/test_file_webp_metadata.py index 9fa20e403..a2a05f96b 100644 --- a/Tests/test_file_webp_metadata.py +++ b/Tests/test_file_webp_metadata.py @@ -30,6 +30,15 @@ def test_read_exif_metadata(): assert exif_data == expected_exif +def test_read_exif_metadata_without_prefix(): + with Image.open("Tests/images/flower2.webp") as im: + # Assert prefix is not present + assert im.info["exif"][:6] != b"Exif\x00\x00" + + exif = im.getexif() + assert exif[305] == "Adobe Photoshop CS6 (Macintosh)" + + def test_write_exif_metadata(): file_path = "Tests/images/flower.jpg" test_buffer = BytesIO() diff --git a/src/PIL/Image.py b/src/PIL/Image.py index d64093df7..038829213 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -3289,7 +3289,9 @@ class Exif(MutableMapping): if not data: return - self.fp = io.BytesIO(data[6:]) + if data.startswith(b"Exif\x00\x00"): + data = data[6:] + self.fp = io.BytesIO(data) self.head = self.fp.read(8) # process dictionary from . import TiffImagePlugin