reftable/block: fix use of uninitialized memory when binsearch fails

When doing the binary search through our restart offsets we may hit an error in case `restart_needle_less()` fails to decode the record at the given offset. While we correctly detect this case and error out, it will cause us to call `reftable_record_release()` on the yet-uninitialized record. Fix this by initializing the record earlier. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 3, 2026 at 14:58 UTC 986590f1f7e9aa2771175e01cba5e2680ff62c1f
1 file changed +4 -4
reftable/block.c
+4 -4
@@ -517,6 +517,10 @@ int block_iter_seek_key(struct block_iter *it, struct reftable_buf *want)
517 int err = 0;
518 size_t i;
519
520 + err = reftable_record_init(&rec, reftable_block_type(it->block));
521 + if (err < 0)
522 + goto done;
523 +
524 /*
525 * Perform a binary search over the block's restart points, which
526 * avoids doing a linear scan over the whole block. Like this, we
@@ -558,10 +562,6 @@ int block_iter_seek_key(struct block_iter *it, struct reftable_buf *want)
562 else
563 it->next_off = it->block->header_off + 4;
564
561 - err = reftable_record_init(&rec, reftable_block_type(it->block));
562 - if (err < 0)
563 - goto done;
564 -
565 /*
566 * We're looking for the last entry less than the wanted key so that
567 * the next call to `block_reader_next()` would yield the wanted