Repository navigation
Raise PlyHeaderParseError instead of UnicodeDecodeError on a non-ASCII header - #91
Merged
Merged
Conversation
_PlyHeaderLines._decode did a strict s.decode('ascii'), so reading a file whose
first bytes are not ASCII (e.g. a PNG or other binary passed by mistake) raised
a bare UnicodeDecodeError instead of the PlyHeaderParseError that a non-PLY
ASCII file already gives. Catch UnicodeDecodeError in _decode and raise
PlyHeaderParseError, which also covers non-ASCII bytes later in the header.
Added a test.
dranjan
self-requested a review
October 8, 2026 22:19
Owner
|
Hey @Erfouni, thanks for the contribution! This shouldn't take long to review. From a cursory glance, I didn't see anything concerning. Also thanks for adding the test. |
dranjan
approved these changes
Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If you pass PlyData.read a file that is not a PLY file and whose first bytes are not ASCII (for example a PNG, or any binary file by mistake), it fails with a bare UnicodeDecodeError:
A non-PLY ASCII file already gives a clean PlyHeaderParseError ("expected 'ply'"), so this makes the binary case behave the same way.
_PlyHeaderLines._decodedoes a stricts.decode('ascii'); I wrapped it to raise PlyHeaderParseError on UnicodeDecodeError. Since_decodeis also used while reading the rest of the header, this covers non-ASCII bytes mid-header too. Valid files are unaffected. Added a test.📚 Documentation preview 📚: https://python-plyfile--91.org.readthedocs.build/en/91/