Fix #114847: Skip past more newlines when parsing PLY files

When parsing PLY files it was possible that the buffer would contain
leading newline characters which were not being accounted for.

Ensure we skip past them each time we refill the buffer. Also properly
return an error string when handling such lines in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/114878
This commit is contained in:
Jesse Yurkovich
2023-11-15 08:31:55 +01:00
committed by Jesse Yurkovich
parent 5c04b477aa
commit 3a312babe6
2 changed files with 8 additions and 1 deletions

View File

@@ -96,8 +96,12 @@ bool PlyReadBuffer::refill_buffer()
pos_ = 0;
buf_used_ = int(read);
/* Find last newline. */
/* Skip past newlines at the front of the buffer and find last newline. */
if (!is_binary_) {
while (pos_ < buf_used_ && is_newline(buffer_[pos_])) {
pos_++;
}
int last_nl = buf_used_;
if (!at_eof_) {
while (last_nl > 0) {

View File

@@ -131,6 +131,9 @@ static int get_index(const PlyElement &element, StringRef property)
static const char *parse_row_ascii(PlyReadBuffer &file, Vector<float> &r_values)
{
Span<char> line = file.read_line();
if (line.is_empty()) {
return "Could not read row of ascii property";
}
/* Parse whole line as floats. */
const char *p = line.data();