commit-graph: check size of commit data chunk
commitb72df612afc12b46ea003732d739d7d746871773
authorJeff King <peff@peff.net>
Mon, 9 Oct 2023 21:05:36 +0000 (9 17:05 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Oct 2023 22:55:01 +0000 (9 15:55 -0700)
tree852fbe053077309ba64483eb7a3a20f421b125a5
parentc0fe9b2da5610bd4ff62d7871dfbbfa0247c7949
commit-graph: check size of commit data chunk

We expect a commit-graph file to have a fixed-size data record for each
commit in the file (and we know the number of commits to expct from the
size of the lookup table). If we encounter a file where this is too
small, we'll look past the end of the chunk (and possibly even off the
mapped memory).

We can fix this by checking the size up front when we record the
pointer.

The included test doesn't segfault, since it ends up reading bytes
from another chunk. But it produces nonsense results, since the values
it reads are garbage. Our test notices this by comparing the output to a
non-corrupted run of the same command (and of course we also check that
the expected error is printed to stderr).

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