summaryrefslogtreecommitdiffstats
path: root/code/AssetLib/MD2/MD2Loader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'code/AssetLib/MD2/MD2Loader.cpp')
-rw-r--r--code/AssetLib/MD2/MD2Loader.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/code/AssetLib/MD2/MD2Loader.cpp b/code/AssetLib/MD2/MD2Loader.cpp
index 99dc70d08..942bc6177 100644
--- a/code/AssetLib/MD2/MD2Loader.cpp
+++ b/code/AssetLib/MD2/MD2Loader.cpp
@@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
-Copyright (c) 2006-2024, assimp team
+Copyright (c) 2006-2025, assimp team
All rights reserved.
@@ -101,7 +101,7 @@ MD2Importer::MD2Importer()
// Returns whether the class can handle the format of the given file.
bool MD2Importer::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool /*checkSig*/) const
{
- static const uint32_t tokens[] = { AI_MD2_MAGIC_NUMBER_LE };
+ static constexpr uint32_t tokens[] = { AI_MD2_MAGIC_NUMBER_LE };
return CheckMagicToken(pIOHandler,pFile,tokens,AI_COUNT_OF(tokens));
}
@@ -319,16 +319,22 @@ void MD2Importer::InternReadFile( const std::string& pFile,
clr.b = clr.g = clr.r = 0.05f;
pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_AMBIENT);
- if (pcSkins->name[0])
+ const ai_uint32 MaxNameLength = AI_MAXLEN - 1; // one byte reserved for \0
+ ai_uint32 iLen = static_cast<ai_uint32>(::strlen(pcSkins->name));
+ bool nameTooLong = iLen > MaxNameLength;
+
+ if (pcSkins->name[0] && !nameTooLong)
{
aiString szString;
- const ai_uint32 iLen = (ai_uint32) ::strlen(pcSkins->name);
- ::memcpy(szString.data,pcSkins->name,iLen);
+ ::memcpy(szString.data, pcSkins->name, iLen);
szString.data[iLen] = '\0';
szString.length = iLen;
pcHelper->AddProperty(&szString,AI_MATKEY_TEXTURE_DIFFUSE(0));
}
+ else if (nameTooLong) {
+ ASSIMP_LOG_WARN("Texture file name is too long. It will be skipped.");
+ }
else{
ASSIMP_LOG_WARN("Texture file name has zero length. It will be skipped.");
}