From 2d994e1a286fac611d43a5a7eca32436d37e87e0 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 5 Jul 2022 22:50:54 +0200 Subject: [PATCH 1/2] Fix possible bad_alloc exception for invalid file - Fuzzer finding - closes https://github.com/assimp/assimp/issues/3417 --- code/AssetLib/Q3D/Q3DLoader.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/code/AssetLib/Q3D/Q3DLoader.cpp b/code/AssetLib/Q3D/Q3DLoader.cpp index c773bbfcd..719352481 100644 --- a/code/AssetLib/Q3D/Q3DLoader.cpp +++ b/code/AssetLib/Q3D/Q3DLoader.cpp @@ -129,10 +129,20 @@ void Q3DImporter::InternReadFile(const std::string &pFile, unsigned int numTextures = (unsigned int)stream.GetI4(); std::vector materials; - materials.reserve(numMats); + try { + materials.reserve(numMats); + } catch(const std::bad_alloc& e) { + ASSIMP_LOG_ERROR("Invalid alloc for materials."); + throw DeadlyImportError("Invalid Quick3D-file, material allocation failed."); + } std::vector meshes; - meshes.reserve(numMeshes); + try { + meshes.reserve(numMeshes); + } catch(const std::bad_alloc& e) { + ASSIMP_LOG_ERROR("Invalid alloc for meshes."); + throw DeadlyImportError("Invalid Quick3D-file, mesh allocation failed."); + } // Allocate the scene root node pScene->mRootNode = new aiNode(); From eeae6eac2648df70a560659a90f4011fdc2083da Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 5 Jul 2022 23:01:18 +0200 Subject: [PATCH 2/2] Update Q3DLoader.cpp --- code/AssetLib/Q3D/Q3DLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/AssetLib/Q3D/Q3DLoader.cpp b/code/AssetLib/Q3D/Q3DLoader.cpp index 719352481..0bfe16162 100644 --- a/code/AssetLib/Q3D/Q3DLoader.cpp +++ b/code/AssetLib/Q3D/Q3DLoader.cpp @@ -131,7 +131,7 @@ void Q3DImporter::InternReadFile(const std::string &pFile, std::vector materials; try { materials.reserve(numMats); - } catch(const std::bad_alloc& e) { + } catch(const std::bad_alloc&) { ASSIMP_LOG_ERROR("Invalid alloc for materials."); throw DeadlyImportError("Invalid Quick3D-file, material allocation failed."); } @@ -139,7 +139,7 @@ void Q3DImporter::InternReadFile(const std::string &pFile, std::vector meshes; try { meshes.reserve(numMeshes); - } catch(const std::bad_alloc& e) { + } catch(const std::bad_alloc&) { ASSIMP_LOG_ERROR("Invalid alloc for meshes."); throw DeadlyImportError("Invalid Quick3D-file, mesh allocation failed."); }