Ignore IPTC field that is only zero bytes

This commit is contained in:
Andrew Murray 2023-08-04 23:54:05 +10:00
parent fc99a5871e
commit 6bd3ed439a
2 changed files with 14 additions and 1 deletions

View File

@ -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:

View File

@ -58,7 +58,7 @@ class IptcImageFile(ImageFile.ImageFile):
#
# 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]