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

[PATCH v2 3/3] pack-bitmap: add loading corrupt bitmap_index test

From
Lidong Yan via GitGitGadget <gitgitgadget@gmail.com>
Date
May 20, 2025, 09:23 UTC
Message-ID
<5be22d563af714ebb902506f12b4468a5348896c.1747732991.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1962.v2.git.git.1747732991.gitgitgadget@gmail.com>
From: Lidong Yan <502024330056@smail.nju.edu.cn>
This patch add "load corrupt bitmap" test case in t5310-pack-bitmaps.sh.

This test case intentionally corrupt the "xor_offset" field of the first entry. To find position of first entry in *.bitmap, we need to skip 4 ewah_bitmaps before entries. And I add a function `skip_ewah_bitmap()` to do this.

Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
---
 t/t5310-pack-bitmaps.sh | 50 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh
index a62b463eaf09..537a507957bb 100755
--- a/t/t5310-pack-bitmaps.sh
+++ b/t/t5310-pack-bitmaps.sh
@@ -26,6 +26,18 @@ has_any () {
 	grep -Ff "$1" "$2"
 }
 
+skip_ewah_bitmap() {
+	local bitmap="$1" &&
+	local offset="$2" &&
+	local size= &&
+
+	offset=$(($offset + 4)) &&
+	size=0x$(od -An -v -t x1 -j $offset -N 4 $bitmap | tr -d ' \n') &&
+	size=$(($size * 8)) &&
+	offset=$(($offset + 4 + $size + 4)) &&
+	echo $offset
+}
+
 # Since name-hash values are stored in the .bitmap files, add a test
 # that checks that the name-hash calculations are stable across versions.
 # Not exhaustive, but these hashing algorithms would be hard to change
@@ -486,6 +498,44 @@ test_bitmap_cases () {
 			grep "ignoring extra bitmap" trace2.txt
 		)
 	'
+
+	# A `.bitmap` file has the following structure:
+	# | Header | Commits | Trees | Blobs | Tags | Entries... |
+	#
+	# - The header is 32 bytes long when using SHA-1.
+	# - Commits, Trees, Blobs, and Tags are all stored as EWAH bitmaps.
+	#
+	# This test intentionally corrupts the `xor_offset` field of the first entry
+	# to verify robustness against malformed bitmap data.
+	test_expect_success 'load corrupt bitmap' '
+		rm -fr repo &&
+		git init repo &&
+		test_when_finished "rm -fr repo" &&
+		(
+			cd repo &&
+			git config pack.writeBitmapLookupTable '"$writeLookupTable"' &&
+
+			test_commit base &&
+
+			git repack -adb &&
+			bitmap="$(ls .git/objects/pack/pack-*.bitmap)" &&
+			chmod +w "$bitmap" &&
+
+			hdr_sz=$((12 + $(test_oid rawsz))) &&
+			offset=$(skip_ewah_bitmap $bitmap $hdr_sz) &&
+			offset=$(skip_ewah_bitmap $bitmap $offset) &&
+			offset=$(skip_ewah_bitmap $bitmap $offset) &&
+			offset=$(skip_ewah_bitmap $bitmap $offset) &&
+			offset=$((offset + 4)) &&
+
+			printf '\161' |
+				dd of=$bitmap count=1 bs=1 conv=notrunc seek=$offset &&
+
+			git rev-list --count HEAD > expect &&
+			git rev-list --use-bitmap-index --count HEAD > actual &&
+			test_cmp expect actual
+		)
+	'
 }
 
 test_bitmap_cases
-- 
gitgitgadget
Previous: Junio C HamanoNext: Taylor Blau
Message 13 of 45 in “pack-bitmap: fix memory leak if `load_bitmap_entries_v1` failed”
  1. pack-bitmap: fix memory leak if `load_bitmap_entries_v1` failedLidong Yan via GitGitGadget, May 12, 2025
  2. Jeff KingMay 12, 2025
  3. Taylor BlauMay 13, 2025
  4. Junio C HamanoMay 14, 2025
  5. Jeff KingMay 14, 2025
  6. lidongyanMay 15, 2025
  7. 0/3 pack-bitmap: fix memory leak if load_bitmap_entries_v1 failedLidong Yan via GitGitGadget, May 20, 2025
  8. 1/3 pack-bitmap: fix memory leak if `load_bitmap_entries_v1` failedLidong Yan via GitGitGadget, May 20, 2025
  9. 2/3 pack-bitmap: fix memory leak if `load_bitmap_entries_v1` failedTaylor Blau via GitGitGadget, May 20, 2025
  10. Taylor BlauMay 21, 2025
  11. lidongyanMay 22, 2025
  12. Junio C HamanoMay 22, 2025
  13. 3/3 pack-bitmap: add loading corrupt bitmap_index testLidong Yan via GitGitGadget, May 20, 2025
  14. Taylor BlauMay 22, 2025
  15. lidongyanMay 22, 2025
  16. Taylor BlauMay 23, 2025
  17. lidongyanMay 23, 2025
  18. 0/2 pack-bitmap: fix memory leak if load_bitmap_entries_v1 failedLidong Yan via GitGitGadget, May 25, 2025
  19. 1/2 pack-bitmap: fix memory leak if `load_bitmap_entries_v1` failedTaylor Blau via GitGitGadget, May 25, 2025
  20. 2/2 pack-bitmap: add load corrupt bitmap testLidong Yan via GitGitGadget, May 25, 2025
  21. 0/2 pack-bitmap: fix memory leak if load_bitmap failedLidong Yan via GitGitGadget, May 25, 2025
  22. 1/2 pack-bitmap: fix memory leak if load_bitmap() failedTaylor Blau via GitGitGadget, May 25, 2025
  23. Junio C HamanoMay 29, 2025
  24. Taylor BlauMay 29, 2025
  25. Junio C HamanoMay 29, 2025
  26. lidongyanMay 30, 2025
  27. 2/2 pack-bitmap: add load corrupt bitmap testLidong Yan via GitGitGadget, May 25, 2025
  28. Junio C HamanoMay 29, 2025
  29. Taylor BlauMay 29, 2025
  30. lidongyanMay 30, 2025
  31. Taylor BlauMay 29, 2025
  32. lidongyanMay 30, 2025
  33. 0/3 pack-bitmap: fix memory leak if load_bitmap failedLidong Yan via GitGitGadget, Jun 3, 2025
  34. 1/3 pack-bitmap: fix memory leak if load_bitmap() failedTaylor Blau via GitGitGadget, Jun 3, 2025
  35. 2/3 pack-bitmap: reword comments in test_bitmap_commits()Lidong Yan via GitGitGadget, Jun 3, 2025
  36. Taylor BlauJun 3, 2025
  37. 3/3 pack-bitmap: add load corrupt bitmap testLidong Yan via GitGitGadget, Jun 3, 2025
  38. Taylor BlauJun 3, 2025
  39. 0/3 pack-bitmap: fix memory leak if load_bitmap failedLidong Yan via GitGitGadget, Jul 1, 2025
  40. 1/3 pack-bitmap: fix memory leak if load_bitmap() failedTaylor Blau via GitGitGadget, Jul 1, 2025
  41. 2/3 pack-bitmap: reword comments in test_bitmap_commits()Lidong Yan via GitGitGadget, Jul 1, 2025
  42. 3/3 pack-bitmap: add load corrupt bitmap testLidong Yan via GitGitGadget, Jul 1, 2025
  43. Junio C HamanoJul 7, 2025
  44. Taylor BlauJul 8, 2025
  45. Junio C HamanoJul 8, 2025

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.