multi-pack-index: verify object offsets
The 'git multi-pack-index verify' command must verify the object offsets stored in the multi-pack-index are correct. There are two ways the offset chunk can be incorrect: the pack-int-id and the object offset. Replace the BUG() statement with a die() statement, now that we may hit a bad pack-int-id during a 'verify' command on a corrupt multi-pack-index, and it is covered by a test. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
d8ac9ee109
commit
cc6af73c02
29
midx.c
29
midx.c
@ -197,7 +197,8 @@ int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
|
||||
struct strbuf pack_name = STRBUF_INIT;
|
||||
|
||||
if (pack_int_id >= m->num_packs)
|
||||
BUG("bad pack-int-id");
|
||||
die(_("bad pack-int-id: %u (%u total packs"),
|
||||
pack_int_id, m->num_packs);
|
||||
|
||||
if (m->packs[pack_int_id])
|
||||
return 0;
|
||||
@ -970,5 +971,31 @@ int verify_midx_file(const char *object_dir)
|
||||
i, oid_to_hex(&oid1), oid_to_hex(&oid2), i + 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < m->num_objects; i++) {
|
||||
struct object_id oid;
|
||||
struct pack_entry e;
|
||||
off_t m_offset, p_offset;
|
||||
|
||||
nth_midxed_object_oid(&oid, m, i);
|
||||
if (!fill_midx_entry(&oid, &e, m)) {
|
||||
midx_report(_("failed to load pack entry for oid[%d] = %s"),
|
||||
i, oid_to_hex(&oid));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (open_pack_index(e.p)) {
|
||||
midx_report(_("failed to load pack-index for packfile %s"),
|
||||
e.p->pack_name);
|
||||
break;
|
||||
}
|
||||
|
||||
m_offset = e.offset;
|
||||
p_offset = find_pack_entry_one(oid.hash, e.p);
|
||||
|
||||
if (m_offset != p_offset)
|
||||
midx_report(_("incorrect object offset for oid[%d] = %s: %"PRIx64" != %"PRIx64),
|
||||
i, oid_to_hex(&oid), m_offset, p_offset);
|
||||
}
|
||||
|
||||
return verify_midx_error;
|
||||
}
|
||||
|
Reference in New Issue
Block a user