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

[PATCH 3/6] rerere: tighten rr-cache dirname check

From
Jeff King <peff@peff.net>
Date
Jan 28, 2021, 06:16 UTC
Message-ID
<YBJW0gRn9SnP6N9d@coredump.intra.peff.net>
In-Reply-To
<YBJVuckmbGriVa//@coredump.intra.peff.net>

We check only that get_sha1_hex() doesn't complain, which means we'd match an all-hex name with trailing cruft after it. This probably doesn't matter much in practice, since there shouldn't be anything else ni the rr-cache directory, but it could possibly cause us to mix up sha1 and sha256 entries (which also shouldn't be intermingled, but could be leftovers from a repository conversion).

Note that "get_sha1_hex()" is a confusing historical name. It is actually using the_hash_algo, so it would be sha256 in a sha256 repo. We'll switch to using parse_oid_hex(), because that conveniently advances our pointer. But it also gets rid of the sha1 name. Arguably it's a little funny to use "object_id" here for something that isn't actually naming an object, but it's unlikely to be a problem (and is contained in a single function).

Signed-off-by: Jeff King <peff@peff.net>
---
This is mostly just an oddity I noticed while touching the code, and
I've never seen triggered in real life.
 rerere.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/rerere.c b/rerere.c
index 7b0c262ac6..e92e305f96 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1181,8 +1181,9 @@ static void prune_one(struct rerere_id *id,
 /* Does the basename in "path" look plausibly like an rr-cache entry? */
 static int is_rr_cache_dirname(const char *path)
 {
-	unsigned char hash[GIT_MAX_RAWSZ];
-	return !get_sha1_hex(path, hash);
+	struct object_id oid;
+	const char *end;
+	return !parse_oid_hex(path, &oid, &end) && !*end;
 }
 
 void rerere_gc(struct repository *r, struct string_list *rr)
-- 
2.30.0.758.gfe500d6872
Previous: Jeff KingNext: Taylor Blau
Message 5 of 15 in “convert hash_pos() to oid_pos()”
  1. 0/6 convert hash_pos() to oid_pos()Jeff King, Jan 28, 2021
  2. 1/6 commit_graft_pos(): take an oid instead of a bare hashJeff King, Jan 28, 2021
  3. Derrick StoleeJan 28, 2021
  4. 2/6 rerere: check dirname format while iterating rr_cache directoryJeff King, Jan 28, 2021
  5. 3/6 rerere: tighten rr-cache dirname checkJeff King, Jan 28, 2021
  6. Taylor BlauJan 28, 2021
  7. Jeff KingJan 28, 2021
  8. Jeff KingJan 28, 2021
  9. Junio C HamanoJan 28, 2021
  10. Junio C HamanoJan 28, 2021
  11. Jeff KingJan 28, 2021
  12. 5/6 hash_pos(): convert to oid_pos()Jeff King, Jan 28, 2021
  13. Taylor BlauJan 28, 2021
  14. Jeff KingJan 29, 2021
  15. 6/6 oid_pos(): access table through const pointersJeff King, Jan 28, 2021

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.