mirror of
https://github.com/git/git.git
synced 2026-01-10 10:13:33 +00:00
reftable/block: fix error handling when searching restart points
When doing the binary search over restart points in a block we need to decode the record keys. This decoding step can result in an error when the block is corrupted, which we indicate to the caller of the binary search by setting `args.error = 1`. But the only caller that exists mishandles this because it in fact performs the error check before calling `binsearch()`. Fix this bug by checking for errors at the right point in time. Furthermore, refactor `binsearch()` so that it aborts the search in case the callback function returns a negative value so that we don't needlessly continue to search the block. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
77307a61d6
commit
f9e88544f5
@@ -387,11 +387,6 @@ int block_reader_seek(struct block_reader *br, struct block_iter *it,
|
||||
int err = 0;
|
||||
size_t i;
|
||||
|
||||
if (args.error) {
|
||||
err = REFTABLE_FORMAT_ERROR;
|
||||
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
|
||||
@@ -405,6 +400,10 @@ int block_reader_seek(struct block_reader *br, struct block_iter *it,
|
||||
* too many record.
|
||||
*/
|
||||
i = binsearch(br->restart_count, &restart_needle_less, &args);
|
||||
if (args.error) {
|
||||
err = REFTABLE_FORMAT_ERROR;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/*
|
||||
* Now there are multiple cases:
|
||||
|
||||
Reference in New Issue
Block a user