test-tool bitmap: reject packs with duplicate objects

The bitmap writer builds its object-to-position map in packing_data, whose hash table permits one entry per OID. The bitmap test helper accepts an arbitrary existing pack, so a pack with duplicate entries calls packlist_alloc() twice for the same OID and trips its internal BUG(). Detect duplicate OIDs while ingesting the pack and die before calling packlist_alloc(). This preserves the internal uniqueness check for other callers while making unsupported helper input fail gracefully. Reuse t5308's existing duplicate pack to exercise the fatal diagnostic. Signed-off-by: Taylor Blau <ttaylorr@openai.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Jul 24, 2026 at 16:06 UTC 89810d5493ca5e74a56ba33fa8c91910dd381788
2 files changed +10
t/helper/test-bitmap.c
+3
@@ -50,6 +50,9 @@ static int add_packed_object(const struct object_id *oid,
50
51 oi.typep = &type;
52
53 + if (packlist_find(packed, oid))
54 + die("pack contains duplicate object %s", oid_to_hex(oid));
55 +
56 entry = packlist_alloc(packed, oid);
57 entry->idx.offset = nth_packed_object_offset(pack, pos);
58 if (packed_object_info(NULL, pack, entry->idx.offset, &oi) < 0)
t/t5308-pack-detect-duplicates.sh
+7
@@ -59,6 +59,13 @@ test_expect_success 'index-pack will allow duplicate objects by default' '
59 git index-pack --stdin <dups.pack
60 '
61
62 +test_expect_success 'bitmap writer rejects duplicate objects' '
63 + pack=$(ls .git/objects/pack/pack-*.pack) &&
64 + test_must_fail test-tool bitmap write "$(basename "$pack")" \
65 + </dev/null 2>err &&
66 + test_grep "fatal: pack contains duplicate object" err
67 +'
68 +
69 test_expect_success 'create batch-check test vectors' '
70 cat >input <<-EOF &&
71 $LO_SHA1