]> git.ipfire.org Git - thirdparty/git.git/commit - builtin/fsck.c
fsck: validate .rev file header
authorDerrick Stolee <derrickstolee@github.com>
Mon, 17 Apr 2023 16:21:41 +0000 (16:21 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Apr 2023 21:39:05 +0000 (14:39 -0700)
commit5a6072f631dcf4d9f65e83b08d14c82e2af45dd8
tree4868d4798a2d84684f77a1c09788876db317bf79
parent5f658d1b577722111564f51962d6af33d1fe96c6
fsck: validate .rev file header

While parsing a .rev file, we check the header information to be sure it
makes sense. This happens before doing any additional validation such as
a checksum or value check. In order to differentiate between a bad
header and a non-existent file, we need to update the API for loading a
reverse index.

Make load_pack_revindex_from_disk() non-static and specify that a
positive value means "the file does not exist" while other errors during
parsing are negative values. Since an invalid header prevents setting up
the structures we would use for further validations, we can stop at that
point.

The place where we can distinguish between a missing file and a corrupt
file is inside load_revindex_from_disk(), which is used both by pack
rev-indexes and multi-pack-index rev-indexes. Some tests in t5326
demonstrate that it is critical to take some conditions to allow
positive error signals.

Add tests that check the three header values.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fsck.c
pack-bitmap.c
pack-revindex.c
pack-revindex.h
t/t5325-reverse-index.sh