Merge pull request #6124 from radarhere/exif

This commit is contained in:
Hugo van Kemenade 2022-03-23 17:01:22 +02:00 committed by GitHub
commit 3cce863ec8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -666,6 +666,19 @@ class TestImage:
assert not fp.closed
def test_empty_exif(self):
with Image.open("Tests/images/exif.png") as im:
exif = im.getexif()
assert dict(exif) != {}
# Test that exif data is cleared after another load
exif.load(None)
assert dict(exif) == {}
# Test loading just the EXIF header
exif.load(b"Exif\x00\x00")
assert dict(exif) == {}
@mark_if_feature_version(
pytest.mark.valgrind_known_error, "libjpeg_turbo", "2.0", reason="Known Failing"
)

View File

@ -3485,12 +3485,12 @@ class Exif(MutableMapping):
self._loaded_exif = data
self._data.clear()
self._ifds.clear()
if data and data.startswith(b"Exif\x00\x00"):
data = data[6:]
if not data:
self._info = None
return
if data.startswith(b"Exif\x00\x00"):
data = data[6:]
self.fp = io.BytesIO(data)
self.head = self.fp.read(8)
# process dictionary