Browse Source

Fix Stack-buffer-overflow READ in aiMaterial::AddBinaryProperty

Alex 2 years ago
parent
commit
f4d3b6e862
1 changed files with 3 additions and 3 deletions
  1. 3 3
      code/AssetLib/MDL/MDLMaterialLoader.cpp

+ 3 - 3
code/AssetLib/MDL/MDLMaterialLoader.cpp

@@ -493,12 +493,12 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
 
         aiString szFile;
         const size_t iLen = strlen((const char *)szCurrent);
-        size_t iLen2 = iLen + 1;
-        iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2;
+        size_t iLen2 = iLen > MAXLEN - 1 ? MAXLEN - 1: iLen;
         memcpy(szFile.data, (const char *)szCurrent, iLen2);
+        szFile.data[iLen2] = '\0';
         szFile.length = static_cast<ai_uint32>(iLen2);
 
-        szCurrent += iLen2;
+        szCurrent += iLen2 + 1;
 
         // place this as diffuse texture
         pcMatOut->AddProperty(&szFile, AI_MATKEY_TEXTURE_DIFFUSE(0));