Bläddra i källkod

Merge pull request #2970 from ms-maxvollmer/FBXMeshGeometry_checksizes_fix

Added missing checks for tempData and uvIndices sizes in all cases
Kim Kulling 5 år sedan
förälder
incheckning
5eb040c744
1 ändrade filer med 32 tillägg och 6 borttagningar
  1. 32 6
      code/FBX/FBXMeshGeometry.cpp

+ 32 - 6
code/FBX/FBXMeshGeometry.cpp

@@ -448,6 +448,12 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
         std::vector<T> tempData;
 		ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
 
+		if (tempData.size() != vertex_count) {
+			FBXImporter::LogError(Formatter::format("length of input data unexpected for ByVertice mapping: ")
+								  << tempData.size() << ", expected " << vertex_count);
+			return;
+		}
+
         data_out.resize(vertex_count);
 		for (size_t i = 0, e = tempData.size(); i < e; ++i) {
 
@@ -461,10 +467,23 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
 		std::vector<T> tempData;
 		ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
 
-        data_out.resize(vertex_count);
+		if (tempData.size() != vertex_count) {
+			FBXImporter::LogError(Formatter::format("length of input data unexpected for ByVertice mapping: ")
+								  << tempData.size() << ", expected " << vertex_count);
+			return;
+		}
 
         std::vector<int> uvIndices;
         ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));
+
+		if (uvIndices.size() != vertex_count) {
+			FBXImporter::LogError(Formatter::format("length of input data unexpected for ByVertice mapping: ")
+								  << uvIndices.size() << ", expected " << vertex_count);
+			return;
+		}
+
+		data_out.resize(vertex_count);
+
         for (size_t i = 0, e = uvIndices.size(); i < e; ++i) {
 
             const unsigned int istart = mapping_offsets[i], iend = istart + mapping_counts[i];
@@ -493,15 +512,22 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
 		std::vector<T> tempData;
 		ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
 
-        data_out.resize(vertex_count);
+		if (tempData.size() != vertex_count) {
+			FBXImporter::LogError(Formatter::format("length of input data unexpected for ByPolygonVertex mapping: ")
+								  << tempData.size() << ", expected " << vertex_count);
+			return;
+		}
 
         std::vector<int> uvIndices;
         ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));
 
-        if (uvIndices.size() != vertex_count) {
-            FBXImporter::LogError("length of input data unexpected for ByPolygonVertex mapping");
-            return;
-        }
+		if (uvIndices.size() != vertex_count) {
+			FBXImporter::LogError(Formatter::format("length of input data unexpected for ByPolygonVertex mapping: ")
+								  << uvIndices.size() << ", expected " << vertex_count);
+			return;
+		}
+
+		data_out.resize(vertex_count);
 
         const T empty;
         unsigned int next = 0;