Skip to content

Commit 42bfcaa

Browse files
committed
When IFD is missing, connect get_ifd() dictionary to Exif
1 parent 6a9acfa commit 42bfcaa

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Tests/test_image.py

+8
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,14 @@ def test_empty_exif(self) -> None:
769769
exif.load(b"Exif\x00\x00")
770770
assert not dict(exif)
771771

772+
def test_empty_get_ifd(self) -> None:
773+
exif = Image.Exif()
774+
ifd = exif.get_ifd(0x8769)
775+
assert ifd == {}
776+
777+
ifd[36864] = b"0220"
778+
assert exif.get_ifd(0x8769) == {36864: b"0220"}
779+
772780
@mark_if_feature_version(
773781
pytest.mark.valgrind_known_error, "libjpeg_turbo", "2.0", reason="Known Failing"
774782
)

src/PIL/Image.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4073,7 +4073,7 @@ def get_ifd(self, tag):
40734073
else:
40744074
# Interop
40754075
self._ifds[tag] = self._get_ifd_dict(tag_data, tag)
4076-
ifd = self._ifds.get(tag, {})
4076+
ifd = self._ifds.setdefault(tag, {})
40774077
if tag == ExifTags.IFD.Exif and self._hidden_data:
40784078
ifd = {
40794079
k: v

0 commit comments

Comments
 (0)