summaryrefslogtreecommitdiff
path: root/midx.c
diff options
context:
space:
mode:
authorDamien Robert <damien.olivier.robert@gmail.com>2020-03-28 22:18:22 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-03-28 23:50:40 (GMT)
commit796d61cdc09c8f3068403965531f27fd11c739e9 (patch)
treee64c267961f2d46d417031d9ae8bfdc71b8e678e /midx.c
parent274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925 (diff)
downloadgit-796d61cdc09c8f3068403965531f27fd11c739e9.zip
git-796d61cdc09c8f3068403965531f27fd11c739e9.tar.gz
git-796d61cdc09c8f3068403965531f27fd11c739e9.tar.bz2
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 <damien.olivier.robert+git@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'midx.c')
-rw-r--r--midx.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/midx.c b/midx.c
index 1527e46..a520e26 100644
--- a/midx.c
+++ b/midx.c
@@ -923,6 +923,12 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
cur_chunk = 0;
num_chunks = large_offsets_needed ? 5 : 4;
+ if (packs.nr - dropped_packs == 0) {
+ error(_("no pack files to index."));
+ result = 1;
+ goto cleanup;
+ }
+
written = write_midx_header(f, num_chunks, packs.nr - dropped_packs);
chunk_ids[cur_chunk] = MIDX_CHUNKID_PACKNAMES;
@@ -1124,6 +1130,15 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
i, oid_fanout1, oid_fanout2, i + 1);
}
+ if (m->num_objects == 0) {
+ midx_report(_("the midx contains no oid"));
+ /*
+ * Remaining tests assume that we have objects, so we can
+ * return here.
+ */
+ return verify_midx_error;
+ }
+
if (flags & MIDX_PROGRESS)
progress = start_sparse_progress(_("Verifying OID order in multi-pack-index"),
m->num_objects - 1);