From 3bd55822cd81930231db9bcb3bdc53deeeb56736 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 24 Apr 2025 13:26:58 +1000 Subject: [PATCH] Handle IPTC TIFF tags with incorrect type --- Tests/test_file_iptc.py | 16 +++++++++++----- src/PIL/IptcImagePlugin.py | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Tests/test_file_iptc.py b/Tests/test_file_iptc.py index c6c0c1aab..07335c269 100644 --- a/Tests/test_file_iptc.py +++ b/Tests/test_file_iptc.py @@ -5,7 +5,7 @@ from io import BytesIO, StringIO import pytest -from PIL import Image, IptcImagePlugin +from PIL import Image, IptcImagePlugin, TiffImagePlugin, TiffTags from .helper import assert_image_equal, hopper @@ -75,13 +75,19 @@ def test_getiptcinfo_zero_padding() -> None: def test_getiptcinfo_tiff() -> None: - # Arrange + expected = {(1, 90): b"\x1b%G", (2, 0): b"\xcf\xc0"} + with Image.open("Tests/images/hopper.Lab.tif") as im: - # Act iptc = IptcImagePlugin.getiptcinfo(im) - # Assert - assert iptc == {(1, 90): b"\x1b%G", (2, 0): b"\xcf\xc0"} + assert iptc == expected + + # Test with LONG tag type + with Image.open("Tests/images/hopper.Lab.tif") as im: + im.tag_v2.tagtype[TiffImagePlugin.IPTC_NAA_CHUNK] = TiffTags.LONG + iptc = IptcImagePlugin.getiptcinfo(im) + + assert iptc == expected def test_getiptcinfo_tiff_none() -> None: diff --git a/src/PIL/IptcImagePlugin.py b/src/PIL/IptcImagePlugin.py index 60ab7c83f..9df498e26 100644 --- a/src/PIL/IptcImagePlugin.py +++ b/src/PIL/IptcImagePlugin.py @@ -219,7 +219,7 @@ def getiptcinfo( # get raw data from the IPTC/NAA tag (PhotoShop tags the data # as 4-byte integers, so we cannot use the get method...) try: - data = im.tag_v2[TiffImagePlugin.IPTC_NAA_CHUNK] + data = im.tag_v2._tagdata[TiffImagePlugin.IPTC_NAA_CHUNK] except KeyError: pass