Skip to content

Commit 3bd5582

Browse files
committed
Handle IPTC TIFF tags with incorrect type
1 parent 58e4874 commit 3bd5582

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Tests/test_file_iptc.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
from PIL import Image, IptcImagePlugin
8+
from PIL import Image, IptcImagePlugin, TiffImagePlugin, TiffTags
99

1010
from .helper import assert_image_equal, hopper
1111

@@ -75,13 +75,19 @@ def test_getiptcinfo_zero_padding() -> None:
7575

7676

7777
def test_getiptcinfo_tiff() -> None:
78-
# Arrange
78+
expected = {(1, 90): b"\x1b%G", (2, 0): b"\xcf\xc0"}
79+
7980
with Image.open("Tests/images/hopper.Lab.tif") as im:
80-
# Act
8181
iptc = IptcImagePlugin.getiptcinfo(im)
8282

83-
# Assert
84-
assert iptc == {(1, 90): b"\x1b%G", (2, 0): b"\xcf\xc0"}
83+
assert iptc == expected
84+
85+
# Test with LONG tag type
86+
with Image.open("Tests/images/hopper.Lab.tif") as im:
87+
im.tag_v2.tagtype[TiffImagePlugin.IPTC_NAA_CHUNK] = TiffTags.LONG
88+
iptc = IptcImagePlugin.getiptcinfo(im)
89+
90+
assert iptc == expected
8591

8692

8793
def test_getiptcinfo_tiff_none() -> None:

src/PIL/IptcImagePlugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def getiptcinfo(
219219
# get raw data from the IPTC/NAA tag (PhotoShop tags the data
220220
# as 4-byte integers, so we cannot use the get method...)
221221
try:
222-
data = im.tag_v2[TiffImagePlugin.IPTC_NAA_CHUNK]
222+
data = im.tag_v2._tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]
223223
except KeyError:
224224
pass
225225

0 commit comments

Comments
 (0)