]> git.ipfire.org Git - thirdparty/git.git/commit - commit-graph.c
commit-graph: simplify parse_commit_graph() #1
authorSZEDER Gábor <szeder.dev@gmail.com>
Fri, 5 Jun 2020 13:00:29 +0000 (13:00 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 Jun 2020 19:28:49 +0000 (12:28 -0700)
commit2ad4f1a7c43cac4ba52cff56f9090d3322c67224
treedc6639ba39c54bf64a3eff22faea35cdc06a9870
parentfa7965309e709e6dcd59c38fc6743d17d82d538b
commit-graph: simplify parse_commit_graph() #1

While we iterate over all entries of the Chunk Lookup table we make
sure that we don't attempt to read past the end of the mmap-ed
commit-graph file, and check in each iteration that the chunk ID and
offset we are about to read is still within the mmap-ed memory region.
However, these checks in each iteration are not really necessary,
because the number of chunks in the commit-graph file is already known
before this loop from the just parsed commit-graph header.

So let's check that the commit-graph file is large enough for all
entries in the Chunk Lookup table before we start iterating over those
entries, and drop those per-iteration checks.  While at it, take into
account the size of everything that is necessary to have a valid
commit-graph file, i.e. the size of the header, the size of the
mandatory OID Fanout chunk, and the size of the signature in the
trailer as well.

Note that this necessitates the change of the error message as well,
and, consequently, have to update the 'detect incorrect chunk count'
test in 't5318-commit-graph.sh' as well.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit-graph.c
t/t5318-commit-graph.sh