Thread (7 messages) read the whole thread 7 messages, 2 authors, 6d ago
COOLING6d

[PATCH 4/5] test-tool bitmap: reject packs with duplicate objects

From: Taylor Blau <hidden>
Date: 2026-07-24 21:06:26
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
 t/helper/test-bitmap.c            | 3 +++
 t/t5308-pack-detect-duplicates.sh | 7 +++++++
 2 files changed, 10 insertions(+)
diff --git a/t/helper/test-bitmap.c b/t/helper/test-bitmap.c
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)
diff --git a/t/t5308-pack-detect-duplicates.sh b/t/t5308-pack-detect-duplicates.sh
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
-- 
2.55.0.383.gde07827a19
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help