浏览代码

MDL: Limit max texture sizes

- closes https://github.com/assimp/assimp/issues/6022
Kim Kulling 6 月之前
父节点
当前提交
5d2a748231
共有 1 个文件被更改,包括 7 次插入0 次删除
  1. 7 0
      code/AssetLib/MDL/MDLMaterialLoader.cpp

+ 7 - 0
code/AssetLib/MDL/MDLMaterialLoader.cpp

@@ -209,6 +209,8 @@ void MDLImporter::CreateTexture_3DGS_MDL4(const unsigned char *szData,
     return;
     return;
 }
 }
 
 
+static const uint32_t MaxTextureSize = 4096;
+
 // ------------------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------------------
 // Load color data of a texture and convert it to our output format
 // Load color data of a texture and convert it to our output format
 void MDLImporter::ParseTextureColorData(const unsigned char *szData,
 void MDLImporter::ParseTextureColorData(const unsigned char *szData,
@@ -219,6 +221,11 @@ void MDLImporter::ParseTextureColorData(const unsigned char *szData,
 
 
     // allocate storage for the texture image
     // allocate storage for the texture image
     if (do_read) {
     if (do_read) {
+        // check for max texture sizes
+        if (pcNew->mWidth > MaxTextureSize || pcNew->mHeight > MaxTextureSize) {
+            throw DeadlyImportError("Invalid MDL file. A texture is too big.");
+        }
+      
         if(pcNew->mWidth != 0 && pcNew->mHeight > UINT_MAX/pcNew->mWidth) {
         if(pcNew->mWidth != 0 && pcNew->mHeight > UINT_MAX/pcNew->mWidth) {
             throw DeadlyImportError("Invalid MDL file. A texture is too big.");
             throw DeadlyImportError("Invalid MDL file. A texture is too big.");
         }
         }