From 72242d312f2e8ee3fd2981eefd435eadafe5f9c1 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Tue, 17 Nov 2026 21:05:14 +0300 Subject: [PATCH] allocator: Fix find_free() returning a block past the end when full An allocator of 2-63 blocks has a single-level mask with no parent bit to mark it full, and the mask bits past the end are always zero. So find_free() on a full allocator returned the first index past the end instead of UINT64_MAX. Store v1 then submitted a big write past the end of its data area (the bounds assert in dequeue_write() fires) instead of failing it with ENOSPC. Store v2 and vitastor-disk raw-resize use the same call. Check the leaf index against the allocator size, and cover sizes 2, 63 and 64 in test_allocator. --- src/test/test_allocator.cpp | 3 +++ src/util/allocator.cpp | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/test_allocator.cpp b/src/test/test_allocator.cpp index 5b524740..9d207bbd 100644 --- a/src/test/test_allocator.cpp +++ b/src/test/test_allocator.cpp @@ -44,5 +44,8 @@ int main(int narg, char *args[]) alloc_all(8192); alloc_all(8062); alloc_all(4096); + alloc_all(64); + alloc_all(63); + alloc_all(2); return 0; } diff --git a/src/util/allocator.cpp b/src/util/allocator.cpp index 3088d683..b1c70991 100644 --- a/src/util/allocator.cpp +++ b/src/util/allocator.cpp @@ -135,7 +135,8 @@ uint64_t allocator_t::find_free() offset += p2; p2 = p2 * 64; } - return addr; + // A full single-level mask (size < 64) still has zero bits past the end + return addr < size ? addr : UINT64_MAX; } uint64_t allocator_t::get_free_count() -- 2.47.3