]> git.ipfire.org Git - thirdparty/git.git/commit
reftable/basics: fix OOB read on binary search of empty range
authorPatrick Steinhardt <ps@pks.im>
Wed, 24 Jun 2026 08:23:06 +0000 (10:23 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Jun 2026 16:30:25 +0000 (09:30 -0700)
commitd5040a8b2b8b7b4377fcec7f79f3d4dc35f628fc
treef5a2e9654892a0db361740831497dd48d3fc0cf6
parenta4a83defdbe6dbb0643a8e6a9f1b5dd86c0ad8ab
reftable/basics: fix OOB read on binary search of empty range

`binsearch()` performs a binary search over a range of `sz` elements by
repeatedly calling the comparison function with indices into that range.
When the range is empty though, there is no valid index to call the
comparison function with. We still end up executing the comparison
function though with an index of 0, which of course will cause an
out-of-bounds read.

Return early when the range is empty.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reftable/basics.c
t/unit-tests/u-reftable-basics.c