Merge pull request #1636 from aavenel/fix_1623

Fix #1623 : crash when loading multiple PLY files
pull/1640/head^2
Kim Kulling 2017-12-17 09:38:55 +01:00 committed by GitHub
commit 99f2721611
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 3 deletions

View File

@ -91,9 +91,9 @@ namespace
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer // Constructor to be privately used by Importer
PLYImporter::PLYImporter() PLYImporter::PLYImporter()
: mBuffer() : mBuffer(nullptr)
, pcDOM() , pcDOM(nullptr)
, mGeneratedMesh(NULL){ , mGeneratedMesh(nullptr){
// empty // empty
} }
@ -196,7 +196,10 @@ void PLYImporter::InternReadFile(const std::string& pFile,
if (!PLY::DOM::ParseInstance(streamedBuffer, &sPlyDom, this)) if (!PLY::DOM::ParseInstance(streamedBuffer, &sPlyDom, this))
{ {
if (mGeneratedMesh != NULL) if (mGeneratedMesh != NULL)
{
delete(mGeneratedMesh); delete(mGeneratedMesh);
mGeneratedMesh = nullptr;
}
streamedBuffer.close(); streamedBuffer.close();
throw DeadlyImportError("Invalid .ply file: Unable to build DOM (#1)"); throw DeadlyImportError("Invalid .ply file: Unable to build DOM (#1)");
@ -211,7 +214,10 @@ void PLYImporter::InternReadFile(const std::string& pFile,
if (!PLY::DOM::ParseInstanceBinary(streamedBuffer, &sPlyDom, this, bIsBE)) if (!PLY::DOM::ParseInstanceBinary(streamedBuffer, &sPlyDom, this, bIsBE))
{ {
if (mGeneratedMesh != NULL) if (mGeneratedMesh != NULL)
{
delete(mGeneratedMesh); delete(mGeneratedMesh);
mGeneratedMesh = nullptr;
}
streamedBuffer.close(); streamedBuffer.close();
throw DeadlyImportError("Invalid .ply file: Unable to build DOM (#2)"); throw DeadlyImportError("Invalid .ply file: Unable to build DOM (#2)");
@ -220,7 +226,10 @@ void PLYImporter::InternReadFile(const std::string& pFile,
else else
{ {
if (mGeneratedMesh != NULL) if (mGeneratedMesh != NULL)
{
delete(mGeneratedMesh); delete(mGeneratedMesh);
mGeneratedMesh = nullptr;
}
streamedBuffer.close(); streamedBuffer.close();
throw DeadlyImportError("Invalid .ply file: Unknown file format"); throw DeadlyImportError("Invalid .ply file: Unknown file format");
@ -230,7 +239,10 @@ void PLYImporter::InternReadFile(const std::string& pFile,
{ {
AI_DEBUG_INVALIDATE_PTR(this->mBuffer); AI_DEBUG_INVALIDATE_PTR(this->mBuffer);
if (mGeneratedMesh != NULL) if (mGeneratedMesh != NULL)
{
delete(mGeneratedMesh); delete(mGeneratedMesh);
mGeneratedMesh = nullptr;
}
streamedBuffer.close(); streamedBuffer.close();
throw DeadlyImportError("Invalid .ply file: Missing format specification"); throw DeadlyImportError("Invalid .ply file: Missing format specification");
@ -252,7 +264,10 @@ void PLYImporter::InternReadFile(const std::string& pFile,
if (mGeneratedMesh->mNumVertices < 3) if (mGeneratedMesh->mNumVertices < 3)
{ {
if (mGeneratedMesh != NULL) if (mGeneratedMesh != NULL)
{
delete(mGeneratedMesh); delete(mGeneratedMesh);
mGeneratedMesh = nullptr;
}
streamedBuffer.close(); streamedBuffer.close();
throw DeadlyImportError("Invalid .ply file: Not enough " throw DeadlyImportError("Invalid .ply file: Not enough "
@ -289,6 +304,7 @@ void PLYImporter::InternReadFile(const std::string& pFile,
pScene->mNumMeshes = 1; pScene->mNumMeshes = 1;
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes]; pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
pScene->mMeshes[0] = mGeneratedMesh; pScene->mMeshes[0] = mGeneratedMesh;
mGeneratedMesh = nullptr;
// generate a simple node structure // generate a simple node structure
pScene->mRootNode = new aiNode(); pScene->mRootNode = new aiNode();

View File

@ -85,6 +85,18 @@ TEST_F(utPLYImportExport, exportTest_Success ) {
#endif // ASSIMP_BUILD_NO_EXPORT #endif // ASSIMP_BUILD_NO_EXPORT
//Test issue 1623, crash when loading two PLY files in a row
TEST_F(utPLYImportExport, importerMultipleTest) {
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", 0);
EXPECT_NE(nullptr, scene);
scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", 0);
EXPECT_NE(nullptr, scene);
}
TEST_F( utPLYImportExport, vertexColorTest ) { TEST_F( utPLYImportExport, vertexColorTest ) {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/PLY/float-color.ply", 0 ); const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/PLY/float-color.ply", 0 );