Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion plyfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,11 @@ def _decode(s):
"""
if isinstance(s, str):
return s
return s.decode('ascii')
try:
return s.decode('ascii')
except UnicodeDecodeError:
raise PlyHeaderParseError(
"header contains non-ASCII characters")

def __iter__(self):
"""
Expand Down
7 changes: 7 additions & 0 deletions test/test_plyfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,13 @@ def test_header_parse_error(s, line):
assert e.exc_val.line == line


def test_header_non_ascii_bytes():
# a non-PLY binary file (e.g. a PNG) should raise PlyHeaderParseError,
# not a raw UnicodeDecodeError from the non-ASCII header bytes
with Raises(PlyHeaderParseError):
PlyData.read(BytesIO(b'\x89PNG\r\n\x1a\n' + b'\x00' * 40))


invalid_arrays = [
numpy.zeros((2, 2)),
numpy.array([(0, (0, 0))],
Expand Down
Loading