From 45bc4e320970f3d7f952fd0d0fa762322d407bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Sat, 8 Jan 2022 20:46:28 +0100 Subject: [PATCH] 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. --- source/blender/io/alembic/intern/abc_reader_mesh.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc index adf1a3e241c..83ca3399db5 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@ -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(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(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());