Skip to content

Commit

Permalink
Ignore IPTC field that is only zero bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Aug 4, 2023
1 parent fc99a58 commit 6bd3ed4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Tests/test_file_iptc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ def test_getiptcinfo_jpg_found():
assert iptc[(2, 101)] == b"Hungary"


def test_getiptcinfo_zero_padding():
# Arrange
with Image.open(TEST_FILE) as im:
im.info["photoshop"][0x0404] += b"\x00\x00\x00"

# Act
iptc = IptcImagePlugin.getiptcinfo(im)

# Assert
assert isinstance(iptc, dict)
assert len(iptc) == 3


def test_getiptcinfo_tiff_none():
# Arrange
with Image.open("Tests/images/hopper.tif") as im:
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/IptcImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def field(self):
#
# get a IPTC field header
s = self.fp.read(5)
if not len(s):
if not s.strip(b"\x00"):
return None, 0

tag = s[1], s[2]
Expand Down

0 comments on commit 6bd3ed4

Please sign in to comment.