diff --git a/code/Common/Assimp.cpp b/code/Common/Assimp.cpp index 073ce2ad7..ee7f3fed8 100644 --- a/code/Common/Assimp.cpp +++ b/code/Common/Assimp.cpp @@ -354,9 +354,10 @@ ASSIMP_API const aiScene *aiApplyCustomizedPostProcessing(const aiScene *scene, void CallbackToLogRedirector(const char *msg, char *dt) { ai_assert(nullptr != msg); ai_assert(nullptr != dt); - LogStream *s = (LogStream *)dt; - - s->write(msg); + LogStream *stream = (LogStream *)dt; + if (stream != nullptr) { + stream->write(msg); + } } static LogStream *DefaultStream = nullptr; diff --git a/code/PostProcessing/SortByPTypeProcess.cpp b/code/PostProcessing/SortByPTypeProcess.cpp index d16f0e59f..162ddab6f 100644 --- a/code/PostProcessing/SortByPTypeProcess.cpp +++ b/code/PostProcessing/SortByPTypeProcess.cpp @@ -136,6 +136,9 @@ void SortByPTypeProcess::Execute(aiScene *pScene) { for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) { aiMesh *const mesh = pScene->mMeshes[i]; if (mesh->mPrimitiveTypes == 0) { + for (size_t idx = 0; idx < outMeshes.size(); ++idx) { + delete outMeshes[idx]; + } throw DeadlyImportError("Mesh with invalid primitive type: ", mesh->mName.C_Str()); } diff --git a/test/models/fuzzer_data/clusterfuzz-testcase-minimized-assimp_fuzzer-4751812606885888 b/test/models/fuzzer_data/clusterfuzz-testcase-minimized-assimp_fuzzer-4751812606885888 new file mode 100644 index 000000000..36861a7e3 Binary files /dev/null and b/test/models/fuzzer_data/clusterfuzz-testcase-minimized-assimp_fuzzer-4751812606885888 differ diff --git a/test/unit/utSortByPType.cpp b/test/unit/utSortByPType.cpp index 5ebdc6f9e..2c1ceca33 100644 --- a/test/unit/utSortByPType.cpp +++ b/test/unit/utSortByPType.cpp @@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "Common/ScenePreprocessor.h" #include "PostProcessing/SortByPTypeProcess.h" #include +#include using namespace std; using namespace Assimp; @@ -202,3 +203,9 @@ TEST_F(SortByPTypeProcessTest, SortByPTypeStep) { } } } + +TEST_F(SortByPTypeProcessTest, issue389327770Test) { + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/fuzzer_data/clusterfuzz-testcase-minimized-assimp_fuzzer-4751812606885888", aiProcessPreset_TargetRealtime_Fast); + EXPECT_NE(nullptr, scene); +}