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

We neither check nor record the size of the generations chunk we parse
from a commit-graph file. This should have one uint32_t for each commit
in the file; if it is smaller (due to corruption, etc), we may read
outside the mapped memory.

The included test segfaults without this patch, as it shrinks the size
considerably (and the chunk is near the end of the file, so we read off
the end of the array rather than accidentally reading another chunk).

We can fix this by checking the size up front (like we do for other
fixed-size chunks, like CDAT).

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