From 42bfcaa2d4371b7a1312848c0f5f6cfefcaaa9cb Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 13 Jul 2024 12:46:15 +1000 Subject: [PATCH] When IFD is missing, connect get_ifd() dictionary to Exif --- Tests/test_image.py | 8 ++++++++ src/PIL/Image.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Tests/test_image.py b/Tests/test_image.py index 4fdc41791..77be58261 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -769,6 +769,14 @@ class TestImage: exif.load(b"Exif\x00\x00") assert not dict(exif) + def test_empty_get_ifd(self) -> None: + exif = Image.Exif() + ifd = exif.get_ifd(0x8769) + assert ifd == {} + + ifd[36864] = b"0220" + assert exif.get_ifd(0x8769) == {36864: b"0220"} + @mark_if_feature_version( pytest.mark.valgrind_known_error, "libjpeg_turbo", "2.0", reason="Known Failing" ) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 565abe71d..9a3e4efa4 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -4073,7 +4073,7 @@ class Exif(_ExifBase): else: # Interop self._ifds[tag] = self._get_ifd_dict(tag_data, tag) - ifd = self._ifds.get(tag, {}) + ifd = self._ifds.setdefault(tag, {}) if tag == ExifTags.IFD.Exif and self._hidden_data: ifd = { k: v