diff --git a/source/blender/io/ply/importer/ply_import_data.cc b/source/blender/io/ply/importer/ply_import_data.cc index 4b364e8e599..ce6732c5b6c 100644 --- a/source/blender/io/ply/importer/ply_import_data.cc +++ b/source/blender/io/ply/importer/ply_import_data.cc @@ -437,6 +437,12 @@ static const char *load_face_element(PlyReadBuffer &file, if (count < 1 || count > 255) { return "Invalid face size, must be between 1 and 255"; } + /* Previous python based importer was accepting faces with fewer + * than 3 vertices, and silently dropping them. */ + if (count < 3) { + fprintf(stderr, "PLY Importer: ignoring face %i (%i vertices)\n", i, count); + continue; + } for (int j = 0; j < count; j++) { int index; @@ -467,15 +473,22 @@ static const char *load_face_element(PlyReadBuffer &file, scratch.resize(count * data_type_size[prop.type]); file.read_bytes(scratch.data(), scratch.size()); - ptr = scratch.data(); - if (header.type == PlyFormatType::BINARY_BE) { - endian_switch_array((uint8_t *)ptr, data_type_size[prop.type], count); + /* Previous python based importer was accepting faces with fewer + * than 3 vertices, and silently dropping them. */ + if (count < 3) { + fprintf(stderr, "PLY Importer: ignoring face %i (%i vertices)\n", i, count); } - for (int j = 0; j < count; ++j) { - uint32_t index = get_binary_value(prop.type, ptr); - data->face_vertices.append(index); + else { + ptr = scratch.data(); + if (header.type == PlyFormatType::BINARY_BE) { + endian_switch_array((uint8_t *)ptr, data_type_size[prop.type], count); + } + for (int j = 0; j < count; ++j) { + uint32_t index = get_binary_value(prop.type, ptr); + data->face_vertices.append(index); + } + data->face_sizes.append(count); } - data->face_sizes.append(count); /* Skip any properties after vertex indices. */ for (int j = prop_index + 1; j < element.properties.size(); j++) {