commit-graph: check bounds when accessing BIDX chunk
commit581e0f8b189b5b3d50aae16be09941ab6fccf335
authorJeff King <peff@peff.net>
Mon, 9 Oct 2023 21:05:53 +0000 (9 17:05 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Oct 2023 22:55:01 +0000 (9 15:55 -0700)
tree74282fb5bb83885549d2ae1664fbee2641bb26f3
parent920f400e919c7c51f81adc6989cdd52630220783
commit-graph: check bounds when accessing BIDX chunk

We load the bloom_filter_indexes chunk using pair_chunk(), so we have no
idea how big it is. This can lead to out-of-bounds reads if it is
smaller than expected, since we index it based on the number of commits
found elsewhere in the graph file.

We can check the chunk size up front, like we do for CDAT and other
chunks with one fixed-size record per commit.

The test case demonstrates the problem. It actually won't segfault,
because we end up reading random data from the follow-on chunk (BDAT in
this case), and the bounds checks added in the previous patch complain.
But this is by no means assured, and you can craft a commit-graph file
with BIDX at the end (or a smaller BDAT) that does segfault.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit-graph.c
t/t4216-log-bloom.sh