git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Taylor Blau <ttaylorr@openai.com>
Date
Jul 24, 2026, 21:06 UTC
Message-ID
<355a9f849c1a98f47dad3edfc8251e28ee179272.1784927134.git.ttaylorr@openai.com>
In-Reply-To
<cover.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 <ttaylorr@openai.com>
---
 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
Previous: Taylor BlauNext: Taylor Blau
Message 5 of 7 in “packfile: harden handling of packs with duplicate entries”
  1. 0/5 packfile: harden handling of packs with duplicate entriesTaylor Blau, Jul 24, 2026
  2. 1/5 t5308: test reverse indexes with duplicate objectsTaylor Blau, Jul 24, 2026
  3. 2/5 packfile: recover delta cycles through duplicate entriesTaylor Blau, Jul 24, 2026
  4. 3/5 midx: verify duplicate pack entries by OID and offsetTaylor Blau, Jul 24, 2026
  5. 4/5 test-tool bitmap: reject packs with duplicate objectsTaylor Blau, Jul 24, 2026
  6. 5/5 pack-bitmap: handle duplicate pack entries during MIDX reuseTaylor Blau, Jul 24, 2026
  7. Junio C HamanoJul 24, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.