Check entry sizes in blockstore_heap during loading

This commit is contained in:
Vitaliy Filippov
2026-06-16 20:34:52 +03:00
parent cd51f14a90
commit 1be51f903c
+6 -7
View File
@@ -122,6 +122,8 @@ uint32_t heap_entry_t::get_size(blockstore_heap_t *heap)
} }
if (type() == BS_HEAP_SMALL_WRITE || type() == BS_HEAP_INTENT_WRITE) if (type() == BS_HEAP_SMALL_WRITE || type() == BS_HEAP_INTENT_WRITE)
{ {
if (size < sizeof(heap_small_write_t))
return heap->get_small_entry_size(0, 0);
return heap->get_small_entry_size(small().offset, small().len); return heap->get_small_entry_size(small().offset, small().len);
} }
return heap->get_simple_entry_size(); return heap->get_simple_entry_size();
@@ -364,14 +366,11 @@ corrupted_object:
return EDOM; return EDOM;
} }
} }
if (((wr->entry_type & BS_HEAP_TYPE) == BS_HEAP_SMALL_WRITE || if (wr->size != wr->get_size(this))
(wr->entry_type & BS_HEAP_TYPE) == BS_HEAP_INTENT_WRITE) &&
wr->size < sizeof(heap_small_write_t))
{ {
// Small writes require accessing offset & len to calculate correct length, // Check entry size
// so require at least sizeof(heap_small_write_t) for them fprintf(stderr, "Error: entry %jx:%jx v%ju has invalid size in metadata block %u at %u (%u != %u bytes)\n",
fprintf(stderr, "Error: entry %jx:%jx v%ju has invalid size in metadata block %u at %u (%u < min %zu bytes)\n", wr->inode, wr->stripe, wr->version, block_num, block_offset, wr->size, wr->get_size(this));
wr->inode, wr->stripe, wr->version, block_num, block_offset, wr->size, sizeof(heap_small_write_t));
goto corrupted_object; goto corrupted_object;
} }
if (wr->entry_type == BS_HEAP_COMMIT && !wr->version) if (wr->entry_type == BS_HEAP_COMMIT && !wr->version)