Skip to content

Commit

Permalink
NUL terminates Ascii value
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail-iurkov committed Jan 20, 2022
1 parent 6e483ac commit f0ead75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions piexif/_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ def _read_tag(self, pointer):
format = TYPE_FORMAT.get(value_type, None)

if format is None:
raw_value = self.tiftag[data_pointer:data_pointer+value_length]
# Ascii, Undefined and unknown types
if value_type == TYPES.Ascii:
# Crop ending zero
value_length = max(0, value_length - 1)
raw_value = self.tiftag[data_pointer:data_pointer+value_length]
raw_value = raw_value.split(b'\0')[0]
values = (raw_value, )
else:
# Unpacked types
Expand Down
8 changes: 8 additions & 0 deletions tests/s_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,14 @@ def test_truncated_ifd(self):
ifd = er.get_ifd_dict(8, "0th", True)
self.assertEqual(ifd[ImageIFD.ProcessingSoftware], b"FOO")

def test_ascii_zero(self):
b1 = b"MM\x00\x2a\x00\x00\x00\x08"
b2 = b"\x00\x01" + b"\x00\x0b\x00\x02\x00\x00\x00\x04" + b"F\x00OO"
er = piexif._load._ExifReader(b1 + b2)
er.endian_mark = ">"
ifd = er.get_ifd_dict(8, "0th", True)
self.assertEqual(ifd[ImageIFD.ProcessingSoftware], b"F")

def test_split_into_segments_fail1(self):
with self.assertRaises(InvalidImageDataError):
_common.split_into_segments(b"I'm not JPEG")
Expand Down

0 comments on commit f0ead75

Please sign in to comment.