From 648a836c5ca79d769442fd9fb9664ed77ff3c1d1 Mon Sep 17 00:00:00 2001 From: Garux Date: Wed, 1 May 2024 00:05:57 +0500 Subject: [PATCH] fix assimp ASE loader crash when *MATERIAL_COUNT or *NUMSUBMTLS is not specified or is 0 code was doing vector[0u - 1] dereference in this case --- libs/assimp/code/AssetLib/ASE/ASEParser.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libs/assimp/code/AssetLib/ASE/ASEParser.cpp b/libs/assimp/code/AssetLib/ASE/ASEParser.cpp index a2884b8d..8d074da1 100644 --- a/libs/assimp/code/AssetLib/ASE/ASEParser.cpp +++ b/libs/assimp/code/AssetLib/ASE/ASEParser.cpp @@ -482,6 +482,13 @@ void Parser::ParseLV1MaterialListBlock() { continue; } if (TokenMatch(filePtr, "MATERIAL", 8)) { + // ensure we have at least one material allocated + if (iMaterialCount == 0) { + LogWarning("*MATERIAL_COUNT unspecified or 0"); + iMaterialCount = 1; + m_vMaterials.resize(iOldMaterialCount + iMaterialCount, Material("INVALID")); + } + unsigned int iIndex = 0; ParseLV4MeshLong(iIndex); @@ -634,6 +641,12 @@ void Parser::ParseLV2MaterialBlock(ASE::Material &mat) { } // submaterial chunks if (TokenMatch(filePtr, "SUBMATERIAL", 11)) { + // ensure we have at least one material allocated + if (iNumSubMaterials == 0) { + LogWarning("*NUMSUBMTLS unspecified or 0"); + iNumSubMaterials = 1; + mat.avSubMaterials.resize(iNumSubMaterials, Material("INVALID SUBMATERIAL")); + } unsigned int iIndex = 0; ParseLV4MeshLong(iIndex);