I/O: Harden geometry import for invalid data

* Use int64_t to avoid overflows, following our C++ guidelines.
* Add various index range checks for code that runs before mesh
  validation.
* Match some loop iteration variables to the size type.
* Ensure number of elements fit into int where needed.
* OBJ vertex weight import issue with || true (debug leftover?).
* USD invalid shape key size check (> instead of >=).
* USD now preserves vertex positions for some invalid topology,
  this the reason for usd_mesh_custom.txt test update.
* Note FBX import has fewer checks because ufbx already handles most.

Some of these are defensive, some prevent actual crashes. Tests were
added for various crashes.

These checks are meant to run in combination with mesh validation. We
try to prevent out of bounds access before validation but leave invalid
topology detection to the validation code.

Pull Request: https://projects.blender.org/blender/blender/pulls/158307
This commit is contained in:
Brecht Van Lommel 2026-04-28 15:25:26 +02:00
parent c57d6debff
commit 3a572c5745
41 changed files with 657 additions and 194 deletions

View file

@ -141,6 +141,13 @@ class USDImportTest(AbstractUSDTest):
self.assertEqual(len(mesh.vertices), 5)
self.assertEqual(len(mesh.polygons[0].vertices), 5)
def test_import_mesh_invalid_topology(self):
"""Importer must not crash on invalid topology."""
infile = str(self.testdir / "usd_mesh_invalid_topology.usda")
res = bpy.ops.wm.usd_import(filepath=infile)
self.assertEqual({'FINISHED'}, res, f"Unable to import USD file {infile}")
def test_import_mesh_topology_change(self):
"""Test importing meshes with changing topology over time."""