From 681c32d5ecb34dbd4792f93fa7f238dd5bd91c37 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Wed, 1 Apr 2015 16:23:28 +0300 Subject: [PATCH] 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. --- code/ACLoader.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/ACLoader.cpp b/code/ACLoader.cpp index d3f45918a..47f0b8622 100644 --- a/code/ACLoader.cpp +++ b/code/ACLoader.cpp @@ -274,6 +274,9 @@ void AC3DImporter::LoadObjectSection(std::vector& objects) SkipSpaces(&buffer); unsigned int t = strtoul10(buffer,&buffer); + if (t >= std::numeric_limits::max() / sizeof(aiVector3D)) { + throw DeadlyImportError("AC3D: Too many vertices, would run out of memory"); + } obj.vertices.reserve(t); for (unsigned int i = 0; i < t;++i) {