midx.c: fix an integer underflow
authorDamien Robert <redacted>
Sat, 28 Mar 2020 22:18:22 +0000 (23:18 +0100)
committerJunio C Hamano <redacted>
Sat, 28 Mar 2020 23:50:40 +0000 (16:50 -0700)
commit796d61cdc09c8f3068403965531f27fd11c739e9
treee64c267961f2d46d417031d9ae8bfdc71b8e678e
parent274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925
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 <redacted>
Signed-off-by: Junio C Hamano <redacted>
midx.c
t/t5319-multi-pack-index.sh
t/t5319/no-objects.midx [new file with mode: 0644]
git clone https://git.99rst.org/PROJECT