Fix T94713: Alembic crash with empty frames and velocities

Some software or processing tools (videogrammetry in this case) may
export malformed files with velocity data even when the frame is empty
for some reason. We need to explicity compare the data size with the
vertex size, and refuse to load the attribute if there is a data size
mismatch.
This commit is contained in:
Kévin Dietrich 2022-01-08 20:46:28 +01:00
parent d5e73fa13d
commit 45bc4e3209
Notes: blender-bot 2023-02-14 07:30:31 +01:00
Referenced by issue #98471, cycles render preview fail when changing material color
Referenced by issue #95889, Alembic crashes on Linux
Referenced by issue #94713, Crashes playing Alembic with empty frames and velocities
1 changed files with 7 additions and 3 deletions

View File

@ -463,13 +463,17 @@ static void read_velocity(const V3fArraySamplePtr &velocities,
const CDStreamConfig &config,
const float velocity_scale)
{
const int num_velocity_vectors = static_cast<int>(velocities->size());
if (num_velocity_vectors != config.mesh->totvert) {
/* Files containing videogrammetry data may be malformed and export velocity data on missing
* frames (most likely by copying the last valid data). */
return;
}
CustomDataLayer *velocity_layer = BKE_id_attribute_new(
&config.mesh->id, "velocity", CD_PROP_FLOAT3, ATTR_DOMAIN_POINT, nullptr);
float(*velocity)[3] = (float(*)[3])velocity_layer->data;
const int num_velocity_vectors = static_cast<int>(velocities->size());
BLI_assert(num_velocity_vectors == config.mesh->totvert);
for (int i = 0; i < num_velocity_vectors; i++) {
const Imath::V3f &vel_in = (*velocities)[i];
copy_zup_from_yup(velocity[i], vel_in.getValue());