Commit: d5a1c5457063e0e4b779d672074f5f82ead36ebe
Author: makowalski
Date:   Sun Jul 11 20:20:23 2021 -0400
Branches: usd-importer-T81257-merge
https://developer.blender.org/rBd5a1c5457063e0e4b779d672074f5f82ead36ebe

USD importer: normals count bounds check.

Added bounds check for vertex varying normals, to
prevent crashes reading badly formed meshes, where
the number of normals doesn't match the number
of points. Also guarding against null mesh.

===================================================================

M       source/blender/io/usd/intern/usd_reader_mesh.cc

===================================================================

diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc 
b/source/blender/io/usd/intern/usd_reader_mesh.cc
index 0a748ee013c..2ca8d174775 100644
--- a/source/blender/io/usd/intern/usd_reader_mesh.cc
+++ b/source/blender/io/usd/intern/usd_reader_mesh.cc
@@ -538,11 +538,22 @@ void USDMeshReader::read_colors(Mesh *mesh, const double 
motionSampleTime)
 
 void USDMeshReader::process_normals_vertex_varying(Mesh *mesh)
 {
+  if (!mesh) {
+    return;
+  }
+
   if (normals_.empty()) {
     BKE_mesh_calc_normals(mesh);
     return;
   }
 
+  if (normals_.size() != mesh->totvert) {
+    std::cerr << "WARNING: vertex varying normals count mismatch for mesh " << 
prim_path_
+              << std::endl;
+    BKE_mesh_calc_normals(mesh);
+    return;
+  }
+
   for (int i = 0; i < normals_.size(); i++) {
     MVert &mvert = mesh->mvert[i];
     normal_float_to_short_v3(mvert.no, normals_[i].data());

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to