Add various checks to avoid either too large or zero-sized memory allocations
This commit is contained in:
@@ -783,6 +783,11 @@ void MD3Importer::InternReadFile( const std::string& pFile,
|
||||
|
||||
// Allocate output storage
|
||||
pScene->mNumMeshes = pcHeader->NUM_SURFACES;
|
||||
if (pcHeader->NUM_SURFACES == 0) {
|
||||
throw DeadlyImportError("MD3: No surfaces");
|
||||
} else if (pcHeader->NUM_SURFACES > std::numeric_limits<int32_t>::max() / sizeof(aiMesh)) {
|
||||
throw DeadlyImportError("MD3: Too many surfaces, would run out of memory");
|
||||
}
|
||||
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
|
||||
|
||||
pScene->mNumMaterials = pcHeader->NUM_SURFACES;
|
||||
|
||||
Reference in New Issue
Block a user