1
0
mirror of https://github.com/git/git.git synced 2024-10-21 16:18:11 +02:00

Merge branch 'dr/midx-avoid-int-underflow'

When fed a midx that records no objects, some codepaths tried to
loop from 0 through (num_objects-1), which, due to integer
arithmetic wrapping around, made it nonsense operation with out of
bounds array accesses.  The code has been corrected to reject such
an midx file.

* dr/midx-avoid-int-underflow:
  midx.c: fix an integer underflow
This commit is contained in:
Junio C Hamano 2020-04-22 13:42:44 -07:00
commit 8777ec119e
3 changed files with 24 additions and 4 deletions

15
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);

@ -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 () {

BIN
t/t5319/no-objects.midx Normal file

Binary file not shown.