From: Patrick Steinhardt Date: Wed, 24 Jun 2026 08:23:11 +0000 (+0200) Subject: reftable/block: fix use of uninitialized memory when binsearch fails X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=084d11a310c587071ed828423439678ca36a0ab8;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/reftable/block.c b/reftable/block.c index 4d285aefd7..89efce8751 100644 --- a/reftable/block.c +++ b/reftable/block.c @@ -517,6 +517,10 @@ int block_iter_seek_key(struct block_iter *it, struct reftable_buf *want) int err = 0; size_t i; + err = reftable_record_init(&rec, reftable_block_type(it->block)); + if (err < 0) + goto done; + /* * Perform a binary search over the block's restart points, which * 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) else it->next_off = it->block->header_off + 4; - err = reftable_record_init(&rec, reftable_block_type(it->block)); - if (err < 0) - goto done; - /* * We're looking for the last entry less than the wanted key so that * the next call to `block_reader_next()` would yield the wanted