[Bf-blender-cvs] [2307ea88b5f] blender-v2.79-release: Alembic import: fix crash when face color index is out of bounds.

Sybren A. Stüvel noreply at git.blender.org
Thu Aug 17 14:45:37 CEST 2017


Commit: 2307ea88b5fccfbcb80f07ba7c93a7291ba18643
Author: Sybren A. Stüvel
Date:   Tue Aug 15 12:34:40 2017 +0200
Branches: blender-v2.79-release
https://developer.blender.org/rB2307ea88b5fccfbcb80f07ba7c93a7291ba18643

Alembic import: fix crash when face color index is out of bounds.

This can happen with Alembic files exported from Maya. I'm unsure as to the
root cause, but at least this fixes the crash itself.

Thanks to @looch for reporting this with a test file. The test file has to
remain confidential, though, so it's on my workstation only.

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

M	source/blender/alembic/intern/abc_customdata.cc

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

diff --git a/source/blender/alembic/intern/abc_customdata.cc b/source/blender/alembic/intern/abc_customdata.cc
index 1d2bc689027..3380aaf222e 100644
--- a/source/blender/alembic/intern/abc_customdata.cc
+++ b/source/blender/alembic/intern/abc_customdata.cc
@@ -252,6 +252,26 @@ static void read_uvs(const CDStreamConfig &config, void *data,
 	}
 }
 
+static size_t mcols_out_of_bounds_check(
+        const size_t color_index,
+        const size_t array_size,
+        const PropertyHeader &prop_header,
+        bool &r_bounds_warning_given)
+{
+	if (color_index < array_size) {
+		return color_index;
+	}
+
+	if (!r_bounds_warning_given) {
+		std::cerr << "Alembic import: color index out of bounds "
+		             "reading face colors for property "
+		          << prop_header.getName() << std::endl;
+		r_bounds_warning_given = true;
+	}
+
+	return 0;
+}
+
 static void read_custom_data_mcols(const ICompoundProperty &arbGeomParams,
                                    const PropertyHeader &prop_header,
                                    const CDStreamConfig &config,
@@ -303,6 +323,8 @@ static void read_custom_data_mcols(const ICompoundProperty &arbGeomParams,
 
 	size_t face_index = 0;
 	size_t color_index;
+	bool bounds_warning_given = false;
+
 	for (int i = 0; i < config.totpoly; ++i) {
 		MPoly *poly = &mpolys[i];
 		MCol *cface = &cfaces[poly->loopstart + poly->totloop];
@@ -311,9 +333,13 @@ static void read_custom_data_mcols(const ICompoundProperty &arbGeomParams,
 		for (int j = 0; j < poly->totloop; ++j, ++face_index) {
 			--cface;
 			--mloop;
-			color_index = is_facevarying ? face_index : mloop->v;
 
 			if (use_c3f_ptr) {
+				color_index = mcols_out_of_bounds_check(
+				                  is_facevarying ? face_index : mloop->v,
+				                  c3f_ptr->size(),
+				                  prop_header, bounds_warning_given);
+
 				const Imath::C3f &color = (*c3f_ptr)[color_index];
 				cface->a = FTOCHAR(color[0]);
 				cface->r = FTOCHAR(color[1]);
@@ -321,6 +347,11 @@ static void read_custom_data_mcols(const ICompoundProperty &arbGeomParams,
 				cface->b = 255;
 			}
 			else {
+				color_index = mcols_out_of_bounds_check(
+				                  is_facevarying ? face_index : mloop->v,
+				                  c4f_ptr->size(),
+				                  prop_header, bounds_warning_given);
+
 				const Imath::C4f &color = (*c4f_ptr)[color_index];
 				cface->a = FTOCHAR(color[0]);
 				cface->r = FTOCHAR(color[1]);




More information about the Bf-blender-cvs mailing list