Skip to content

Commit f1ab507

Browse files
Fix in VmaBlockMetadata_Linear::CreateAllocationRequest for too large allocations
Fixes #396 - thanks @dm-tesla
1 parent 9b76877 commit f1ab507

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

include/vk_mem_alloc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7808,6 +7808,10 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest(
78087808
VMA_ASSERT(allocType != VMA_SUBALLOCATION_TYPE_FREE);
78097809
VMA_ASSERT(pAllocationRequest != VMA_NULL);
78107810
VMA_HEAVY_ASSERT(Validate());
7811+
7812+
if(allocSize > GetSize())
7813+
return false;
7814+
78117815
pAllocationRequest->size = allocSize;
78127816
return upperAddress ?
78137817
CreateAllocationRequest_UpperAddress(

src/Tests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,6 +3425,14 @@ static void TestVirtualBlocksAlgorithms()
34253425
};
34263426
std::vector<AllocData> allocations;
34273427

3428+
// Test too large allocation
3429+
{
3430+
VmaVirtualAllocationCreateInfo allocCreateInfo = {};
3431+
allocCreateInfo.size = blockCreateInfo.size * 2;
3432+
VmaVirtualAllocation alloc;
3433+
TEST(vmaVirtualAllocate(block, &allocCreateInfo, &alloc, nullptr) < 0);
3434+
}
3435+
34283436
// Make some allocations
34293437
for(size_t i = 0; i < 20; ++i)
34303438
{

0 commit comments

Comments
 (0)