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

[PATCH v2 2/3] t/helper: fix segfault in "dump-reftable -t"

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 1, 2026, 05:39 UTC
Message-ID
<20261001-pks-reftables-fix-timezone-format-v2-2-a4fd1f7cd21a@pks.im>
In-Reply-To
<20261001-pks-reftables-fix-timezone-format-v2-0-a4fd1f7cd21a@pks.im>

The `test-tool dump-reftable` command can be used to dump the on-disk contents of reftables. The "-t" subcommand specifically can be used to dump a single table from disk.

When trying to use this subcommand though one will quickly realize that it is broken, as it always segfaults. The root cause of this segfault is that we try to detect the hash algorithm via the merged table's hash ID. But that hash ID is not the same as Git's understanding of a hash ID, and consequently we fail to look up the correct algorithm. This will then lead to a segfault later on when we try to dereference a NULL pointer.

This breakage went undetected until now because this particular subcommand is not used anywhere in our test suite. So the obvious way to fix the bug is by just removing the code outright. But in the next commit we're about to add a user.

Fix the issue by properly converting between the two hash IDs.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 t/helper/test-reftable.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c
index fc49fafc34..57758936b0 100644
--- a/t/helper/test-reftable.c
+++ b/t/helper/test-reftable.c
@@ -103,7 +103,16 @@ static int dump_table(struct reftable_merged_table *mt)
 	if (err < 0)
 		return err;
 
-	algop = &hash_algos[hash_algo_by_id(reftable_merged_table_hash_id(mt))];
+	switch (reftable_merged_table_hash_id(mt)) {
+	case REFTABLE_HASH_SHA1:
+		algop = &hash_algos[GIT_HASH_SHA1];
+		break;
+	case REFTABLE_HASH_SHA256:
+		algop = &hash_algos[GIT_HASH_SHA256];
+		break;
+	default:
+		die("unknown reftable hash function: %d", reftable_merged_table_hash_id(mt));
+	}
 
 	while (1) {
 		err = reftable_iterator_next_ref(&it, &ref);
-- 
2.56.0.353.g0856645cf6.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 13 of 16 in “refs/reftable: fix on-disk representation of reflog timezones”
  1. 0/3 refs/reftable: fix on-disk representation of reflog timezonesPatrick Steinhardt, Sep 29, 2026
  2. 1/3 date: add helpers to convert between "+HHMM" timezones and minutesPatrick Steinhardt, Sep 29, 2026
  3. Karthik NayakSep 30, 2026
  4. Patrick SteinhardtSep 30, 2026
  5. Karthik NayakOct 1, 2026
  6. Junio C HamanoSep 30, 2026
  7. 2/3 t/helper: fix segfault in "dump-reftable -t"Patrick Steinhardt, Sep 29, 2026
  8. 3/3 refs/reftable: fix on-disk representation of reflog timezonesPatrick Steinhardt, Sep 29, 2026
  9. Karthik NayakSep 30, 2026
  10. Patrick SteinhardtSep 30, 2026
  11. 0/3 refs/reftable: fix on-disk representation of reflog timezonesPatrick Steinhardt, Oct 1, 2026
  12. 1/3 date: add helpers to convert between "+HHMM" timezones and minutesPatrick Steinhardt, Oct 1, 2026
  13. 2/3 t/helper: fix segfault in "dump-reftable -t"Patrick Steinhardt, Oct 1, 2026
  14. 3/3 refs/reftable: fix on-disk representation of reflog timezonesPatrick Steinhardt, Oct 1, 2026
  15. Karthik NayakOct 1, 2026
  16. Junio C HamanoOct 1, 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.