浏览代码

MD3: Check file is big enough to contain all the advertised surfaces

Turo Lamminen 9 年之前
父节点
当前提交
555f533777
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      code/MD3Loader.cpp

+ 8 - 0
code/MD3Loader.cpp

@@ -407,6 +407,14 @@ void MD3Importer::ValidateHeaderOffsets()
         throw DeadlyImportError("Invalid MD3 header: some offsets are outside the file");
     }
 
+	if (pcHeader->NUM_SURFACES > AI_MAX_ALLOC(MD3::Surface)) {
+        throw DeadlyImportError("Invalid MD3 header: too many surfaces, would overflow");
+	}
+
+    if (pcHeader->OFS_SURFACES + pcHeader->NUM_SURFACES * sizeof(MD3::Surface) >= fileSize) {
+        throw DeadlyImportError("Invalid MD3 header: some surfaces are outside the file");
+    }
+
     if (pcHeader->NUM_FRAMES <= configFrameID )
         throw DeadlyImportError("The requested frame is not existing the file");
 }