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

Taylor Blau <[email protected]>
Newsgroups org.kernel.vger.git
Message-ID <355a9f849c1a98f47dad3edfc8251e28ee179272.1784927134.git.ttaylorr@openai.com>
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 <[email protected]>
---
 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.