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
index 8547ef67e2..6f851e0421 100644
--- a/t/helper/test-bitmap.c
+++ b/t/helper/test-bitmap.c
@@ -50,6 +50,9 @@ static int add_packed_object(const struct object_id *oid,
oi.typep = &type;
+ if (packlist_find(packed, oid))
+ die("pack contains duplicate object %s", oid_to_hex(oid));
+
entry = packlist_alloc(packed, oid);
entry->idx.offset = nth_packed_object_offset(pack, pos);
if (packed_object_info(NULL, pack, entry->idx.offset, &oi) < 0)
t/t5308-pack-detect-duplicates.sh
+7
index 493ebbc4af..c6273a1aeb 100755
--- a/t/t5308-pack-detect-duplicates.sh
+++ b/t/t5308-pack-detect-duplicates.sh
@@ -59,6 +59,13 @@ test_expect_success 'index-pack will allow duplicate objects by default' '
git index-pack --stdin <dups.pack
'
+test_expect_success 'bitmap writer rejects duplicate objects' '
+ pack=$(ls .git/objects/pack/pack-*.pack) &&
+ test_must_fail test-tool bitmap write "$(basename "$pack")" \
+ </dev/null 2>err &&
+ test_grep "fatal: pack contains duplicate object" err
+'
+
test_expect_success 'create batch-check test vectors' '
cat >input <<-EOF &&
$LO_SHA1