From a6d7280b8e1c8ac7c0d6ebcf134290836413168c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 10 Mar 2020 17:15:29 +0100 Subject: Fix T74200: Alembic import crashes Blender I've added a very minimal mesh validation before the Alembic mesh is actually converted to a Blender mesh. This prevents a specific crash with an example file attached to T74200. --- source/blender/io/alembic/intern/abc_reader_mesh.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'source/blender/io') diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc index a4e412695c3..ec74fb2137e 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@ -564,6 +564,21 @@ Mesh *AbcMeshReader::read_mesh(Mesh *existing_mesh, const Alembic::Abc::Int32ArraySamplePtr &face_indices = sample.getFaceIndices(); const Alembic::Abc::Int32ArraySamplePtr &face_counts = sample.getFaceCounts(); + /* Do some very minimal mesh validation. */ + const int poly_count = face_counts->size(); + const int loop_count = face_indices->size(); + /* This is the same test as in poly_to_tri_count(). */ + if (poly_count > 0 && loop_count < poly_count * 2) { + if (err_str != nullptr) { + *err_str = "Invalid mesh; more detail on the console"; + } + printf("Alembic: invalid mesh sample for '%s/%s' at time %f, less than 2 loops per face\n", + m_iobject.getFullName().c_str(), + m_schema.getName().c_str(), + sample_sel.getRequestedTime()); + return existing_mesh; + } + Mesh *new_mesh = NULL; /* Only read point data when streaming meshes, unless we need to create new ones. */ -- cgit v1.2.3