From 9d9a80739df416d89bcd69e1f2532732269a7f67 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 14 May 2025 11:43:12 +0200 Subject: [PATCH] Fix: Fix leak when sortbyp failes with exception (#6166) Co-authored-by: Kim Kulling --- code/Common/Assimp.cpp | 7 ++++--- code/PostProcessing/SortByPTypeProcess.cpp | 3 +++ ...case-minimized-assimp_fuzzer-4751812606885888 | Bin 0 -> 1966 bytes test/unit/utSortByPType.cpp | 7 +++++++ 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 test/models/fuzzer_data/clusterfuzz-testcase-minimized-assimp_fuzzer-4751812606885888 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 0000000000000000000000000000000000000000..36861a7e3108bf9303a95b87685474c8b5152d65 GIT binary patch literal 1966 zcmd5-K~EDw6dn?Y?uNY>5))!{phC2!VcyQ{%U@hH%cRGOfW7TZp?Gt2>deFAXfruCfmaq53TKn0(&Y5al`(Kr6qBu` z`PW$5r}qe>${nl`4Fd*L!KD2wh7-XT*Lyi-CgYxGD2u212L?q4lJ*m!V~fv!w47EO zWfctV_mv};8;4L-!XLcp@)UlBW=pr0@v23%OPW5u1GvZ3Obs;5v8CK>#<*aN2r39( z>qHL_T9+70bIaJ2kleDU(1;=?@s(+=rb|o(9(*2dFZ3YPtm4VD-N^C$b@xqKmhh_Kz22(TZF&1rd8Vw7NA6Ldcymo&Yl$bIwi;n+B0!3HK<`~G zJ*Z2ssOYV%j!Sx|2_cD^9&(cz!)Ocbq+BIP(vY3_@?(4;IatW`yV-OuKa|e)<@=2< zO)rv0F5c_rfG)$p+mANh zBy3LQx`UYnsA;Re6QnD9S(kzKBKj^Dt1ci2FaVn}P8fGg3W5T+1tnB~W!nshB}~!v zIUpKIcH`Z&r4$mWr&8o@U;ceJg^J1I5q(5|;{V(r;CY@Y8&Y#QwHm5t;}>tVLIHau=Oy^%WFMwOSSUG8gJegIH`0&7z|Jn1n-jkKXTR<^KAV?)tCJFJW)>xc~qF literal 0 HcmV?d00001 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); +}