Skip to content

Commit

Permalink
fix ASE loader crash when *MATERIAL_COUNT or *NUMSUBMTLS is not speci…
Browse files Browse the repository at this point in the history
…fied or is 0 (assimp#5559)

code was doing vector[0u - 1] dereference in this case

Co-authored-by: Kim Kulling <[email protected]>
  • Loading branch information
Garux and kimkulling authored May 8, 2024
1 parent c953739 commit 47dbaba
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions code/AssetLib/ASE/ASEParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,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);

Expand Down Expand Up @@ -653,6 +660,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);
Expand Down

0 comments on commit 47dbaba

Please sign in to comment.