]> git.ipfire.org Git - thirdparty/git.git/commitdiff
midx: report checksum mismatches during 'verify'
authorTaylor Blau <me@ttaylorr.com>
Wed, 23 Jun 2021 18:39:15 +0000 (14:39 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 29 Jun 2021 03:36:17 +0000 (20:36 -0700)
'git multi-pack-index verify' inspects the data in an existing MIDX for
correctness by checking that the recorded object offsets are correct,
and so on.

But it does not check that the file's trailing checksum matches the data
that it records. So, if an on-disk corruption happened to occur in the
final few bytes (and all other data was recorded correctly), we would:

  - get a clean result from 'git multi-pack-index verify', but
  - be unable to reuse the existing MIDX when writing a new one (since
    we now check for checksum mismatches before reusing a MIDX)

Teach the 'verify' sub-command to recognize corruption in the checksum
by calling midx_checksum_valid().

Suggested-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
midx.c
t/t5319-multi-pack-index.sh

diff --git a/midx.c b/midx.c
index a12cbbf9287ae5617a0e792329a15b1b0b90c776..9a35b0255d5c04258aeacd0a63c21cdb627e58ce 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -1228,6 +1228,9 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
                return result;
        }
 
+       if (!midx_checksum_valid(m))
+               midx_report(_("incorrect checksum"));
+
        if (flags & MIDX_PROGRESS)
                progress = start_delayed_progress(_("Looking for referenced packfiles"),
                                          m->num_packs);
index d582f370c4264840786bc3647e9081e1b144a252..7609f1ea6416f4e39d62a45e5da26a2427411be3 100755 (executable)
@@ -418,6 +418,11 @@ test_expect_success 'corrupt MIDX is not reused' '
        git multi-pack-index verify
 '
 
+test_expect_success 'verify incorrect checksum' '
+       pos=$(($(wc -c <$objdir/pack/multi-pack-index) - 1)) &&
+       corrupt_midx_and_verify $pos "\377" $objdir "incorrect checksum"
+'
+
 test_expect_success 'repack progress off for redirected stderr' '
        GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack 2>err &&
        test_line_count = 0 err