From: Patrick Steinhardt Date: Thu, 01 Oct 2026 05:39:01 GMT Subject: [PATCH v2 2/3] t/helper: fix segfault in "dump-reftable -t" 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 --- 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