midx: report checksum mismatches during 'verify'

'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>

Taylor Blau committed Jun 23, 2021 at 14:39 UTC f89ecf79888a48e0adf14d0e05c69ee09e853fd5
2 files changed +8
midx.c
+3
@@ -1228,6 +1228,9 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
1228 return result;
1229 }
1230
1231 + if (!midx_checksum_valid(m))
1232 + midx_report(_("incorrect checksum"));
1233 +
1234 if (flags & MIDX_PROGRESS)
1235 progress = start_delayed_progress(_("Looking for referenced packfiles"),
1236 m->num_packs);
t/t5319-multi-pack-index.sh
+5
@@ -418,6 +418,11 @@ test_expect_success 'corrupt MIDX is not reused' '
418 git multi-pack-index verify
419 '
420
421 +test_expect_success 'verify incorrect checksum' '
422 + pos=$(($(wc -c <$objdir/pack/multi-pack-index) - 1)) &&
423 + corrupt_midx_and_verify $pos "\377" $objdir "incorrect checksum"
424 +'
425 +
426 test_expect_success 'repack progress off for redirected stderr' '
427 GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack 2>err &&
428 test_line_count = 0 err