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

[PATCH 3/7] midx: validate incremental MIDX pack IDs

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Sep 17, 2026, 17:52 UTC
Message-ID
<1cf4e5ddb5996423478b7543f7978e58cfcc4eb1.1789667556.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2231.git.1789667556.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

Incremental MIDX support made object-offset pack IDs local to each layer and then converted them to chain-global IDs by adding `num_packs_in_base`. The conversion was introduced by 19419821bac5 (midx: teach `nth_midxed_pack_int_id()` about incremental MIDXs, 2024-08-06). Chain-aware pack preparation followed in 1820bd878c62 (midx: teach `prepare_midx_pack()` about incremental MIDXs, 2024-08-06), but the final `midx_fill_entry()` lookup remained tied to the original layer. Only with 8f909ff4e9e8 (packfile: recover when a multi-pack-index names a removed pack, 2026-08-29) did Coverity point out this issue: a local ID such as `UINT32_MAX` could wrap when the base-pack count was added, producing a plausible but incorrect global ID. After `prepare_midx_pack()` resolved the chain, `midx_fill_entry()` could then underflow or address the wrong layer while indexing the current layer's pack array, causing an invalid memory access and crashing Git.

Validate each local pack ID against its layer's pack count before adding the base count, and obtain the final pack through `nth_midxed_pack()`, which resolves the correct MIDX layer. This prevents an invalid local ID from wrapping during conversion and ensures that the lookup uses the layer identified by the resolved chain-global ID.

Assisted-by: GPT-5.6 Luna
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 midx.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/midx.c b/midx.c
index 6d1c548e3d..6968fc1c00 100644
--- a/midx.c
+++ b/midx.c
@@ -583,10 +583,16 @@ off_t nth_midxed_offset(struct multi_pack_index *m, uint32_t pos)
 
 uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos)
 {
+	uint32_t pack_int_id;
+
 	pos = midx_for_object(&m, pos);
+	pack_int_id = get_be32(m->chunk_object_offsets +
+			       (off_t)pos * MIDX_CHUNK_OFFSET_WIDTH);
+	if (pack_int_id >= m->num_packs)
+		die(_("bad pack-int-id: %"PRIu32" (%"PRIu32" total packs)"),
+		    pack_int_id, m->num_packs);
 
-	return m->num_packs_in_base + get_be32(m->chunk_object_offsets +
-					       (off_t)pos * MIDX_CHUNK_OFFSET_WIDTH);
+	return m->num_packs_in_base + pack_int_id;
 }
 
 enum midx_fill_result midx_fill_entry(struct multi_pack_index *m,
@@ -606,7 +612,7 @@ enum midx_fill_result midx_fill_entry(struct multi_pack_index *m,
 
 	if (prepare_midx_pack(m, pack_int_id))
 		return MIDX_FILL_OWNER_UNAVAILABLE;
-	p = m->packs[pack_int_id - m->num_packs_in_base];
+	p = nth_midxed_pack(m, pack_int_id);
 
 	/*
 	* We are about to tell the caller where they can locate the
-- 
gitgitgadget
Previous: Junio C HamanoNext: Johannes Schindelin via GitGitGadget
Message 7 of 12 in “Fix issues pointed out in Git for Windows by Coverity after merging v2.56.0-rc0”
  1. 0/7 Fix issues pointed out in Git for Windows by Coverity after merging v2.56.0-rc0Johannes Schindelin via GitGitGadget, Sep 17, 2026
  2. 1/7 wrapper: guard writev_in_full() against signed overflowJohannes Schindelin via GitGitGadget, Sep 17, 2026
  3. 2/7 gpg-interface: make signature-prefix matching length-awareJohannes Schindelin via GitGitGadget, Sep 17, 2026
  4. Junio C HamanoSep 17, 2026
  5. Johannes SchindelinSep 18, 2026
  6. Junio C HamanoSep 18, 2026
  7. 3/7 midx: validate incremental MIDX pack IDsJohannes Schindelin via GitGitGadget, Sep 17, 2026
  8. 4/7 rerere: do not record failed conflict resolution dataJohannes Schindelin via GitGitGadget, Sep 17, 2026
  9. Junio C HamanoSep 17, 2026
  10. 5/7 t/unit-tests: check reftable iterator initializationJohannes Schindelin via GitGitGadget, Sep 17, 2026
  11. 6/7 oss-fuzz: handle reftable iterator initialization failuresJohannes Schindelin via GitGitGadget, Sep 17, 2026
  12. 7/7 test-read-midx: check midx_fill_entry() resultJohannes Schindelin via GitGitGadget, Sep 17, 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.