Skip to content

Hangs when there are less elements than the header defines #50

@caleb-krause

Description

@caleb-krause

In parseASCII, we have this loop:

for (size_t iEntry = 0; iEntry < elem.count; iEntry++) {
  
  string line;
  std::getline(inStream, line);
  
  // Some .ply files seem to include empty lines before the start of property data (though this is not specified
  // in the format description). We attempt to recover and parse such files by skipping any empty lines.
  if (!elem.properties.empty()) { // if the element has no properties, the line _should_ be blank, presumably
    while (line.empty()) { // skip lines until we hit something nonempty
  	std::getline(inStream, line);
    }
  }
  
  // Do stuff with the line
}

The outer loop runs elem.count times, which is the number of elements the header says the file will have.

In the inner loop, we loop until we hit a non-blank line.

However, this means if we are at the end of the file when we call while (line.empty()), we will loop endlessly. This can occur when the actual number of elements is less than the number of elements the header specifies.

Here is an example file that will cause a hang:

ply
format ascii 1.0
element vertex 2
property float x
property float y
comment We tell it there are 2 elements but only provide 1
end_header
3 4 

Possible fix

  • Check for EOF when doing getline

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions