Browse Source

X: fix out of bound access.

Kim Kulling 6 years ago
parent
commit
ced080f9f3

+ 5 - 2
code/X/XFileImporter.cpp

@@ -332,7 +332,7 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec
 
                 // collect vertex data for indices of this face
                 for( unsigned int d = 0; d < df.mNumIndices; ++d ) {
-                    df.mIndices[d] = newIndex;
+                    df.mIndices[ d ] = newIndex;
                     const unsigned int newIdx( pf.mIndices[ d ] );
                     if ( newIdx > sourceMesh->mPositions.size() ) {
                         continue;
@@ -344,7 +344,10 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec
                     mesh->mVertices[newIndex] = sourceMesh->mPositions[pf.mIndices[d]];
                     // Normal, if present
                     if ( mesh->HasNormals() ) {
-                        mesh->mNormals[ newIndex ] = sourceMesh->mNormals[ sourceMesh->mNormFaces[ f ].mIndices[ d ] ];
+                        if ( sourceMesh->mNormFaces[ f ].mIndices.size() > d ) {
+                            const size_t idx( sourceMesh->mNormFaces[ f ].mIndices[ d ] );
+                            mesh->mNormals[ newIndex ] = sourceMesh->mNormals[ idx ];
+                        }
                     }
 
                     // texture coord sets

+ 3 - 3
code/X/XFileImporter.h

@@ -58,13 +58,13 @@ struct aiNode;
 namespace Assimp    {
 
 namespace XFile {
-struct Scene;
-struct Node;
+    struct Scene;
+    struct Node;
 }
 
 // ---------------------------------------------------------------------------
 /** The XFileImporter is a worker class capable of importing a scene from a
- * DirectX file .x
+ *   DirectX file .x
  */
 class XFileImporter : public BaseImporter {
 public:

+ 1 - 1
test/models/PLY/cube_test.ply

@@ -1,6 +1,6 @@
 ply
 format ascii 1.0
-comment Created by Open Asset Import Library - http://assimp.sf.net (v4.1.2760932948)
+comment Created by Open Asset Import Library - http://assimp.sf.net (v4.1.3945266037)
 element vertex 8
 property float x
 property float y

+ 3 - 3
test/unit/utBlendImportMaterials.cpp

@@ -133,10 +133,10 @@ TEST_F(BlendImportMaterials, testImportMaterialwith2texturesAnd2TexCoordMappings
 
     // material has 2 diffuse textures
     ASSERT_TRUE(pTest->HasMaterials());
-    EXPECT_EQ(1, pTest->mNumMaterials);
+    EXPECT_EQ(1u, pTest->mNumMaterials);
     const aiMaterial *pMat = pTest->mMaterials[0];
     ASSERT_TRUE(nullptr != pMat);
-    ASSERT_EQ(2, pMat->GetTextureCount(aiTextureType_DIFFUSE));
+    ASSERT_EQ(2u, pMat->GetTextureCount(aiTextureType_DIFFUSE));
     aiString aPath;
     aiTextureMapping tm = aiTextureMapping::aiTextureMapping_OTHER;
     aiReturn result = pMat->GetTexture(aiTextureType_DIFFUSE, 0, &aPath, &tm);
@@ -146,7 +146,7 @@ TEST_F(BlendImportMaterials, testImportMaterialwith2texturesAnd2TexCoordMappings
 
     // mesh has 2 texturecoord sets
     ASSERT_TRUE(pTest->HasMeshes());
-    EXPECT_EQ(1, pTest->mNumMeshes);
+    EXPECT_EQ(1u, pTest->mNumMeshes);
     const aiMesh *pMesh = pTest->mMeshes[0];
     ASSERT_TRUE(nullptr != pMesh);
     ASSERT_TRUE(pMesh->HasTextureCoords(0));