From 796d61cdc09c8f3068403965531f27fd11c739e9 Mon Sep 17 00:00:00 2001 From: Damien Robert Date: Sat, 28 Mar 2020 23:18:22 +0100 Subject: midx.c: fix an integer underflow When verifying a midx index with 0 objects, the m->num_objects - 1 underflows and wraps around to 4294967295. Fix this both by checking that the midx contains at least one oid, and also that we don't write any midx when there is no packfiles. Update the tests to check that `git multi-pack-index write` does not write an midx when there is no objects, and another to check that `git multi-pack-index verify` warns when it verifies an midx with no objects. For this last test, use t5319/no-objects.midx which was generated by an older version of git. Signed-off-by: Damien Robert Signed-off-by: Junio C Hamano --- t/t5319-multi-pack-index.sh | 13 +++++++++---- t/t5319/no-objects.midx | Bin 0 -> 1116 bytes 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 t/t5319/no-objects.midx (limited to 't') diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index 43a7a66c9d..22240fd30b 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -42,10 +42,15 @@ test_expect_success 'setup' ' EOF ' -test_expect_success 'write midx with no packs' ' - test_when_finished rm -f pack/multi-pack-index && - git multi-pack-index --object-dir=. write && - midx_read_expect 0 0 4 . +test_expect_success "don't write midx with no packs" ' + test_must_fail git multi-pack-index --object-dir=. write && + test_path_is_missing pack/multi-pack-index +' + +test_expect_success "Warn if a midx contains no oid" ' + cp "$TEST_DIRECTORY"/t5319/no-objects.midx $objdir/pack/multi-pack-index && + test_must_fail git multi-pack-index verify && + rm $objdir/pack/multi-pack-index ' generate_objects () { diff --git a/t/t5319/no-objects.midx b/t/t5319/no-objects.midx new file mode 100644 index 0000000000..e466b8e086 Binary files /dev/null and b/t/t5319/no-objects.midx differ -- cgit v1.2.3