소스 검색

AC3D: Throw DeadlyImportError when too many vertices instead of out-of-memory exception

Valgrind can't throw an exception when running out of memory. The program
wil just crash. This fixes it in some cases but not all.
Turo Lamminen 10 년 전
부모
커밋
681c32d5ec
1개의 변경된 파일3개의 추가작업 그리고 0개의 파일을 삭제
  1. 3 0
      code/ACLoader.cpp

+ 3 - 0
code/ACLoader.cpp

@@ -274,6 +274,9 @@ void AC3DImporter::LoadObjectSection(std::vector<Object>& objects)
 			SkipSpaces(&buffer);
 			SkipSpaces(&buffer);
 
 
 			unsigned int t = strtoul10(buffer,&buffer);
 			unsigned int t = strtoul10(buffer,&buffer);
+			if (t >= std::numeric_limits<int32_t>::max() / sizeof(aiVector3D)) {
+				throw DeadlyImportError("AC3D: Too many vertices, would run out of memory");
+			}
 			obj.vertices.reserve(t);
 			obj.vertices.reserve(t);
 			for (unsigned int i = 0; i < t;++i)
 			for (unsigned int i = 0; i < t;++i)
 			{
 			{