# fix obj crashes due to out-of-bounds indices in the input files. This fixes models/invalid/malformed.obj and models/invalid/malformed2.obj.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@982 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2011-05-07 11:14:06 +00:00
parent 785b2c0ac3
commit 36d3a60c40
2 changed files with 13 additions and 4 deletions

View File

@ -335,14 +335,20 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
for ( size_t vertexIndex = 0; vertexIndex < pSourceFace->m_pVertices->size(); vertexIndex++ )
{
const unsigned int vertex = pSourceFace->m_pVertices->at( vertexIndex );
ai_assert( vertex < pModel->m_Vertices.size() );
if (vertex >= pModel->m_Vertices.size()) {
throw DeadlyImportError("OBJ: vertex index out of range");
}
pMesh->mVertices[ newIndex ] = pModel->m_Vertices[ vertex ];
// Copy all normals
if ( !pSourceFace->m_pNormals->empty() )
{
const unsigned int normal = pSourceFace->m_pNormals->at( vertexIndex );
ai_assert( normal < pModel->m_Normals.size() );
if (normal >= pModel->m_Normals.size()) {
throw DeadlyImportError("OBJ: vertex normal index out of range");
}
pMesh->mNormals[ newIndex ] = pModel->m_Normals[ normal ];
}
@ -401,8 +407,10 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
const unsigned int numMaterials = (unsigned int) pModel->m_MaterialLib.size();
pScene->mNumMaterials = 0;
if ( pModel->m_MaterialLib.empty() )
if ( pModel->m_MaterialLib.empty() ) {
DefaultLogger::get()->debug("OBJ: no materials specified");
return;
}
pScene->mMaterials = new aiMaterial*[ numMaterials ];
for ( unsigned int matIndex = 0; matIndex < numMaterials; matIndex++ )
@ -435,7 +443,7 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
break;
default:
sm = aiShadingMode_Gouraud;
DefaultLogger::get()->error("OBJ/MTL: Unexpected illumination model (0-2 recognized)");
DefaultLogger::get()->error("OBJ: unexpected illumination model (0-2 recognized)");
}
mat->AddProperty<int>( &sm, 1, AI_MATKEY_SHADING_MODEL);

View File

@ -388,6 +388,7 @@ void ObjFileParser::getMaterialDesc()
{
// Not found, use default material
m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial;
DefaultLogger::get()->error("OBJ: failed to locate material " + strName + ", skipping");
}
else
{