Skip to content

Bug: Binary ply - Line-ending char after the end_header line causes parsing issues #5341

Open

Description

@flogtk

Describe the bug
For a binary ply, if the first char after the "end_header\n" line is '\n' (hence empty line), this char (and line) will be skipped, causing the parser to read the first face element as a vertex part, and shifting everything (all vertices will be incorrect, and faces will be wrong).

To Reproduce
Steps to reproduce the behavior:

  1. Take a binary ply, replace the first char after "end_header\n" by '\n' and try to import it in assimp.
  2. See error, there will probably be something like 'Validation failed: aiMesh::mFaces[4]::mIndices[0] is out of range' (because of the shifting)

Expected behavior
The mesh should be read without any issue.

Platform (please complete the following information):

  • OS: Windows 10
  • Version: reproduced on current master (tag 77a8f01)

Additional context
My mesh is a little endian mesh with faces property 'property list uchar int vertex_indices', since the first line begins with x03x00x00x00x00x01x00x00x00x02, the first char (x03) is considered as the last part of the vertices, hence the 4 first faces are considered to have 0 vertices, and the fifth to have 1 vertex of index 33554432 (which is larger than the total number of vertices, hence the validation error).

The removal of the end of line char error occurs in the PlyParser.cpp file, because of the function SkipSpacesAndLineEnd(std::vector &buffer) called in PLY::Element::ParseElement(IOStreamBuffer &streamBuffer, std::vector &buffer, PLY::Element *pOut), itself called in PLY::DOM::ParseHeader(IOStreamBuffer &streamBuffer, std::vector &buffer, bool isBinary); which will remove the "empty line" after the end of the header

Activity

  1. added
    Bug
    on Nov 23, 2023
  2. added
    PLY
    on Nov 23, 2023
  3. Hyiker commented on Dec 6, 2023

    @Hyiker

    Ran into the same problem recently, I digged out that it may be related to IOStreamBuffer<T>::getNextLine, refered from PLY::Element::ParseElement. This piece of code would eat all following '\n' and '\r' in m_cache:

    while (m_cachePos < m_cacheSize && (m_cache[m_cachePos] == '\r' || m_cache[m_cachePos] == '\n')) {
        ++m_cachePos;
    }

    Perhaps we could offer another function with an argument specifying the max count of LFs to be consumed?

  4. added
    Char encoding
    on Apr 15, 2025
  5. tellypresence commented on Apr 15, 2025

    @tellypresence
    Collaborator

    @flogtk Is this still a problem?

  6. afavray-modjaw commented on Apr 15, 2025

    @afavray-modjaw

    Hello @tellypresence, I'm working with @flogtk and yes, the problem persists.
    We're currently using Assimp 5.2.5. Do you know if the bug has been fixed in later versions?

  7. tellypresence commented on May 13, 2025

    @tellypresence
    Collaborator

    PLY issues tracked via epic #6163

  8. whateverforever commented on Sep 12, 2025

    @whateverforever

    got the same issue, this used to work under focal, but I think the update that happened during the package changes for jammy

  9. whateverforever commented on May 8, 2026

    @whateverforever

    Note for future readers: The above linked issue was live in ubuntu jammy (assimp 5.2.5), in noble (assimp 5.3.1) you get the same error, but this time it comes from a different location in the code, and the fix is the following: b973086 #5692

  10. afavray-modjaw commented on May 11, 2026

    @afavray-modjaw

    Thanks @whateverforever for the notification!
    It looks merged in Assimp 6.0.0, I need to check that ASAP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugChar encodingPLY

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions