mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 10:26:19 +03:00
Merge pull request #5426 from radarhere/undefined_zero
Fixed UNDEFINED TIFF tag of length 0 being changed in roundtrip
This commit is contained in:
commit
d2f2fbacaa
|
@ -185,6 +185,21 @@ def test_iptc(tmp_path):
|
|||
im.save(out)
|
||||
|
||||
|
||||
def test_undefined_zero(tmp_path):
|
||||
# Check that the tag has not been changed since this test was created
|
||||
tag = TiffTags.TAGS_V2[45059]
|
||||
assert tag.type == TiffTags.UNDEFINED
|
||||
assert tag.length == 0
|
||||
|
||||
info = TiffImagePlugin.ImageFileDirectory(b"II*\x00\x08\x00\x00\x00")
|
||||
info[45059] = b"test"
|
||||
|
||||
# Assert that the tag value does not change by setting it to itself
|
||||
original = info[45059]
|
||||
info[45059] = info[45059]
|
||||
assert info[45059] == original
|
||||
|
||||
|
||||
def test_empty_metadata():
|
||||
f = io.BytesIO(b"II*\x00\x08\x00\x00\x00")
|
||||
head = f.read(8)
|
||||
|
|
|
@ -565,7 +565,8 @@ class ImageFileDirectory_v2(MutableMapping):
|
|||
|
||||
if self.tagtype[tag] == TiffTags.UNDEFINED:
|
||||
values = [
|
||||
value.encode("ascii", "replace") if isinstance(value, str) else value
|
||||
v.encode("ascii", "replace") if isinstance(v, str) else v
|
||||
for v in values
|
||||
]
|
||||
elif self.tagtype[tag] == TiffTags.RATIONAL:
|
||||
values = [float(v) if isinstance(v, int) else v for v in values]
|
||||
|
|
Loading…
Reference in New Issue
Block a user