Skip to content

Commit 0c55a2d

Browse files
authored
Merge pull request #7319 from radarhere/iptc
2 parents 5f04b3d + dcfce94 commit 0c55a2d

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

Tests/test_file_iptc.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from io import StringIO
2+
from io import BytesIO, StringIO
33

44
from PIL import Image, IptcImagePlugin
55

@@ -30,6 +30,36 @@ def test_getiptcinfo_jpg_found():
3030
assert iptc[(2, 101)] == b"Hungary"
3131

3232

33+
def test_getiptcinfo_fotostation():
34+
# Arrange
35+
with open(TEST_FILE, "rb") as fp:
36+
data = bytearray(fp.read())
37+
data[86] = 240
38+
f = BytesIO(data)
39+
with Image.open(f) as im:
40+
# Act
41+
iptc = IptcImagePlugin.getiptcinfo(im)
42+
43+
# Assert
44+
for tag in iptc.keys():
45+
if tag[0] == 240:
46+
return
47+
assert False, "FotoStation tag not found"
48+
49+
50+
def test_getiptcinfo_zero_padding():
51+
# Arrange
52+
with Image.open(TEST_FILE) as im:
53+
im.info["photoshop"][0x0404] += b"\x00\x00\x00"
54+
55+
# Act
56+
iptc = IptcImagePlugin.getiptcinfo(im)
57+
58+
# Assert
59+
assert isinstance(iptc, dict)
60+
assert len(iptc) == 3
61+
62+
3363
def test_getiptcinfo_tiff_none():
3464
# Arrange
3565
with Image.open("Tests/images/hopper.tif") as im:

src/PIL/IptcImagePlugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ def field(self):
5858
#
5959
# get a IPTC field header
6060
s = self.fp.read(5)
61-
if not len(s):
61+
if not s.strip(b"\x00"):
6262
return None, 0
6363

6464
tag = s[1], s[2]
6565

6666
# syntax
67-
if s[0] != 0x1C or tag[0] < 1 or tag[0] > 9:
67+
if s[0] != 0x1C or tag[0] not in [1, 2, 3, 4, 5, 6, 7, 8, 9, 240]:
6868
msg = "invalid IPTC/NAA file"
6969
raise SyntaxError(msg)
7070

0 commit comments

Comments
 (0)