Fix #120488: PLY importer crashes on degenerate (1 or 2 vertex) faces

Make it match behavior of the previous Python importer: it was
accepting such faces, and then always calling mesh validation function
that got rid of them. Instead of doing the whole validation cost,
just do not add such faces in the first place.
This commit is contained in:
Aras Pranckevicius
2024-04-11 17:21:16 +03:00
parent 3d1bf4eb74
commit dfb774213d

View File

@@ -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<uint32_t>(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<uint32_t>(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++) {