Browse Source

Merge pull request #1654 from faulesocke/master

Fix buffer overflow in obj loader
Kim Kulling 7 years ago
parent
commit
885c32e8cc
1 changed files with 4 additions and 4 deletions
  1. 4 4
      code/ObjFileImporter.cpp

+ 4 - 4
code/ObjFileImporter.cpp

@@ -448,6 +448,10 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
                 throw DeadlyImportError( "OBJ: vertex index out of range" );
                 throw DeadlyImportError( "OBJ: vertex index out of range" );
             }
             }
 
 
+            if ( pMesh->mNumVertices <= newIndex ) {
+                throw DeadlyImportError("OBJ: bad vertex index");
+            }
+
             pMesh->mVertices[ newIndex ] = pModel->m_Vertices[ vertex ];
             pMesh->mVertices[ newIndex ] = pModel->m_Vertices[ vertex ];
 
 
             // Copy all normals
             // Copy all normals
@@ -479,10 +483,6 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
                 pMesh->mTextureCoords[ 0 ][ newIndex ] = aiVector3D( coord3d.x, coord3d.y, coord3d.z );
                 pMesh->mTextureCoords[ 0 ][ newIndex ] = aiVector3D( coord3d.x, coord3d.y, coord3d.z );
             }
             }
 
 
-            if ( pMesh->mNumVertices <= newIndex ) {
-                throw DeadlyImportError("OBJ: bad vertex index");
-            }
-
             // Get destination face
             // Get destination face
             aiFace *pDestFace = &pMesh->mFaces[ outIndex ];
             aiFace *pDestFace = &pMesh->mFaces[ outIndex ];