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

[PATCH v3 5/9] pack-bitmap: fix pseudo-merge lookup for shared commits

From
Taylor Blau <me@ttaylorr.com>
Date
May 12, 2026, 00:47 UTC
Message-ID
<06e3410d323db13f7fd836ba79cd97586c511227.1778546804.git.me@ttaylorr.com>
In-Reply-To
<cover.1778546804.git.me@ttaylorr.com>

When a commit appears in more than one pseudo-merge group, its entry in the commit lookup table has the high bit set in its offset field, indicating that the offset points to an "extended" table containing the set of pseudo-merges for that commit.

There are three bugs in this path:
 * The `next_ext` offset in `write_pseudo_merges()` undercounts the
   per-entry size of the lookup table (8 vs. 12 bytes).
 * `nth_pseudo_merge_ext()` calls `read_pseudo_merge_commit_at()` on a
   pseudo-merge bitmap offset, misinterpreting it as a 12-byte commit
   table entry.
 * The error check after `pseudo_merge_ext_at()` in
   `apply_pseudo_merges_for_commit()` tests `< -1` instead of `< 0`,
   silently swallowing errors from `error()`.

The first bug is on the write side: each commit lookup entry contains a 4- and 8-byte unsigned value for a total of 12 bytes, but the calculation assumes that the entry only contains 8 bytes of data. This makes `next_ext` too small, so the extended-table offsets that get written point into the middle of the non-extended lookup table rather than past it. The reader then interprets non-extended lookup data as extended entries, producing garbage.

The second bug is on the read side and is independently fatal: even with a correctly positioned extended table, `nth_pseudo_merge_ext()` feeds the offset it reads (which points at pseudo-merge bitmap data) to `read_pseudo_merge_commit_at()`. That function tries to parse 12 bytes as a `pseudo_merge_commit` struct, clobbering `merge->pseudo_merge_ofs` with whatever happens to be at that location. The caller only needs `pseudo_merge_ofs`, so the fix is to store the offset directly rather than re-parsing a commit table entry. The `commit_pos` field is left untouched, retaining the value that `find_pseudo_merge()` set earlier.

The third bug is latent. With the first two fixes applied, the extended table is correctly written and read, so `pseudo_merge_ext_at()` does not fail during normal operation. The `< -1` vs `< 0` distinction only matters when the bitmap file is corrupt or truncated, in which case the error would be silently ignored and the code would proceed with uninitialized data.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 pack-bitmap-write.c             | 2 +-
 pseudo-merge.c                  | 4 ++--
 t/t5333-pseudo-merge-bitmaps.sh | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 86ed6a5d78c..1c8070f99c0 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -877,7 +877,7 @@ static void write_pseudo_merges(struct bitmap_writer *writer,
 
 	next_ext = st_add(hashfile_total(f),
 			  st_mult(kh_size(writer->pseudo_merge_commits),
-				  sizeof(uint64_t)));
+				  sizeof(uint32_t) + sizeof(uint64_t)));
 
 	table_start = hashfile_total(f);
 
diff --git a/pseudo-merge.c b/pseudo-merge.c
index fb71c761792..34e1da00b4e 100644
--- a/pseudo-merge.c
+++ b/pseudo-merge.c
@@ -600,7 +600,7 @@ static int nth_pseudo_merge_ext(const struct pseudo_merge_map *pm,
 		return error(_("out-of-bounds read: (%"PRIuMAX" >= %"PRIuMAX")"),
 			     (uintmax_t)ofs, (uintmax_t)pm->map_size);
 
-	read_pseudo_merge_commit_at(merge, pm->map + ofs);
+	merge->pseudo_merge_ofs = ofs;
 
 	return 0;
 }
@@ -671,7 +671,7 @@ int apply_pseudo_merges_for_commit(const struct pseudo_merge_map *pm,
 		off_t ofs = merge_commit.pseudo_merge_ofs & ~((uint64_t)1<<63);
 		uint32_t i;
 
-		if (pseudo_merge_ext_at(pm, &ext, ofs) < -1) {
+		if (pseudo_merge_ext_at(pm, &ext, ofs) < 0) {
 			warning(_("could not read extended pseudo-merge table "
 				  "for commit %s"),
 				oid_to_hex(&commit->object.oid));
diff --git a/t/t5333-pseudo-merge-bitmaps.sh b/t/t5333-pseudo-merge-bitmaps.sh
index 5411fbf1e04..90459da5e63 100755
--- a/t/t5333-pseudo-merge-bitmaps.sh
+++ b/t/t5333-pseudo-merge-bitmaps.sh
@@ -549,7 +549,7 @@ test_expect_success 'apply pseudo-merges from multiple groups during fill-in' '
 	)
 '
 
-test_expect_failure 'apply pseudo-merges with overlapping groups during fill-in' '
+test_expect_success 'apply pseudo-merges with overlapping groups during fill-in' '
 	test_when_finished "rm -fr pseudo-merge-fill-in-overlap" &&
 	git init pseudo-merge-fill-in-overlap &&
 	(
-- 
2.54.0.76.g9b17dab2cf7
Previous: Taylor BlauNext: Taylor Blau
Message 39 of 46 in “pack-bitmap: fix various pseudo-merge bugs”
  1. 0/8 pack-bitmap: fix various pseudo-merge bugsTaylor Blau, Apr 13, 2026
  2. 1/8 t/helper: add 'test-tool bitmap write' subcommandTaylor Blau, Apr 13, 2026
  3. Junio C HamanoApr 14, 2026
  4. Taylor BlauApr 14, 2026
  5. Junio C HamanoApr 14, 2026
  6. Taylor BlauApr 14, 2026
  7. Junio C HamanoApr 14, 2026
  8. Taylor BlauApr 14, 2026
  9. Elijah NewrenApr 19, 2026
  10. Taylor BlauApr 21, 2026
  11. 2/8 t5333: demonstrate various pseudo-merge bugsTaylor Blau, Apr 13, 2026
  12. Elijah NewrenApr 19, 2026
  13. 3/8 pack-bitmap-write: sort pseudo-merge commit lookup table in pack orderTaylor Blau, Apr 13, 2026
  14. 4/8 pack-bitmap: fix inverted binary search in `pseudo_merge_at()`Taylor Blau, Apr 13, 2026
  15. 5/8 pack-bitmap: fix pseudo-merge lookup for shared commitsTaylor Blau, Apr 13, 2026
  16. 6/8 pack-bitmap: parse commits in `find_pseudo_merge_group_for_ref()`Taylor Blau, Apr 13, 2026
  17. 7/8 pack-bitmap: reject pseudo-merge "sampleRate" of 0Taylor Blau, Apr 13, 2026
  18. Elijah NewrenApr 19, 2026
  19. 8/8 pack-bitmap: prevent pattern leak on pseudo-merge re-assignmentTaylor Blau, Apr 13, 2026
  20. 0/9 pack-bitmap: fix various pseudo-merge bugsTaylor Blau, Apr 21, 2026
  21. 1/9 t/helper: add 'test-tool bitmap write' subcommandTaylor Blau, Apr 21, 2026
  22. 2/9 t5333: demonstrate various pseudo-merge bugsTaylor Blau, Apr 21, 2026
  23. 3/9 pack-bitmap-write: sort pseudo-merge commit lookup table in pack orderTaylor Blau, Apr 21, 2026
  24. 4/9 pack-bitmap: fix inverted binary search in `pseudo_merge_at()`Taylor Blau, Apr 21, 2026
  25. 5/9 pack-bitmap: fix pseudo-merge lookup for shared commitsTaylor Blau, Apr 21, 2026
  26. 6/9 pack-bitmap: parse commits in `find_pseudo_merge_group_for_ref()`Taylor Blau, Apr 21, 2026
  27. 7/9 pack-bitmap: reject pseudo-merge "sampleRate" of 0Taylor Blau, Apr 21, 2026
  28. 8/9 Documentation: fix broken `sampleRate` in gitpacking(7)Taylor Blau, Apr 21, 2026
  29. 9/9 pack-bitmap: prevent pattern leak on pseudo-merge re-assignmentTaylor Blau, Apr 21, 2026
  30. Elijah NewrenApr 22, 2026
  31. Junio C HamanoMay 11, 2026
  32. Taylor BlauMay 12, 2026
  33. Taylor BlauMay 12, 2026
  34. 0/9 pack-bitmap: fix various pseudo-merge bugsTaylor Blau, May 12, 2026
  35. 1/9 t/helper: add 'test-tool bitmap write' subcommandTaylor Blau, May 12, 2026
  36. 2/9 t5333: demonstrate various pseudo-merge bugsTaylor Blau, May 12, 2026
  37. 3/9 pack-bitmap-write: sort pseudo-merge commit lookup table in pack orderTaylor Blau, May 12, 2026
  38. 4/9 pack-bitmap: fix inverted binary search in `pseudo_merge_at()`Taylor Blau, May 12, 2026
  39. 5/9 pack-bitmap: fix pseudo-merge lookup for shared commitsTaylor Blau, May 12, 2026
  40. 6/9 pack-bitmap: parse commits in `find_pseudo_merge_group_for_ref()`Taylor Blau, May 12, 2026
  41. 7/9 pack-bitmap: reject pseudo-merge "sampleRate" of 0Taylor Blau, May 12, 2026
  42. 8/9 Documentation: fix broken `sampleRate` in gitpacking(7)Taylor Blau, May 12, 2026
  43. 9/9 pack-bitmap: prevent pattern leak on pseudo-merge re-assignmentTaylor Blau, May 12, 2026
  44. Junio C HamanoMay 12, 2026
  45. Taylor BlauMay 12, 2026
  46. Junio C HamanoMay 12, 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.