Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle EXIF data truncated to just the header #6124

Merged
merged 1 commit into from Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions Tests/test_image.py
Expand Up @@ -666,6 +666,19 @@ def act(fp):

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"
)
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/Image.py
Expand Up @@ -3478,12 +3478,12 @@ def load(self, data):
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
Expand Down