From 2606c0039fb6ae50a3ed25f298fe9d326c7ca438 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Tue, 29 Nov 2022 16:53:36 +0100 Subject: [PATCH] Fixed potential integer overflow in VmaAllocator_T::AllocateMemoryOfType when maxMemoryAllocationCount Vulkan limit has high value Fixes #300 --- include/vk_mem_alloc.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h index a95631b..844bbff 100644 --- a/include/vk_mem_alloc.h +++ b/include/vk_mem_alloc.h @@ -14475,7 +14475,8 @@ VkResult VmaAllocator_T::AllocateMemoryOfType( // Protection against creating each allocation as dedicated when we reach or exceed heap size/budget, // which can quickly deplete maxMemoryAllocationCount: Don't prefer dedicated allocations when above // 3/4 of the maximum allocation count. - if(m_DeviceMemoryCount.load() > m_PhysicalDeviceProperties.limits.maxMemoryAllocationCount * 3 / 4) + if(m_PhysicalDeviceProperties.limits.maxMemoryAllocationCount < UINT32_MAX / 4 && + m_DeviceMemoryCount.load() > m_PhysicalDeviceProperties.limits.maxMemoryAllocationCount * 3 / 4) { dedicatedPreferred = false; }