Skip to content

Commit

Permalink
Merge pull request #5556 from radarhere/empty_subifd
Browse files Browse the repository at this point in the history
Fixed undefined variable in logging
  • Loading branch information
hugovk committed Jun 26, 2021
2 parents 70ef50c + 61c3907 commit 52856bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Tests/test_file_tiff_metadata.py
Expand Up @@ -376,3 +376,16 @@ def test_too_many_entries():

# Should not raise ValueError.
pytest.warns(UserWarning, lambda: ifd[277])


def test_empty_subifd(tmp_path):
out = str(tmp_path / "temp.jpg")

im = hopper()
exif = im.getexif()
exif[TiffImagePlugin.EXIFIFD] = {}
im.save(out, exif=exif)

with Image.open(out) as reloaded:
exif = reloaded.getexif()
assert exif.get_ifd(TiffImagePlugin.EXIFIFD) == {}
3 changes: 2 additions & 1 deletion src/PIL/TiffImagePlugin.py
Expand Up @@ -826,7 +826,8 @@ def tobytes(self, offset=0):
else:
ifh = b"MM\x00\x2A\x00\x00\x00\x08"
ifd = ImageFileDirectory_v2(ifh)
for ifd_tag, ifd_value in self._tags_v2[tag].items():
values = self._tags_v2[tag]
for ifd_tag, ifd_value in values.items():
ifd[ifd_tag] = ifd_value
data = ifd.tobytes(offset)
else:
Expand Down

0 comments on commit 52856bc

Please sign in to comment.