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

[PATCH 1/4] object-name: do not read a peel suffix as a reflog selector

From
CDCaspar Duregger <caspar.duregger@gmail.com>
Date
Nov 13, 2026, 14:28 UTC
Message-ID
<20261113142804.7465-2-caspar.duregger@gmail.com>
In-Reply-To
<20260212040708.GA1894049@coredump.intra.peff.net>

To find a "@{...}" reflog selector, get_oid_basic() checks that the name ends in '}' and then takes the last "@{" in it.

For "HEAD@{1}^{blob}" the final '}' closes "^{blob}", nevertheless we take "1}^{blob" as the selector. That is not a number, so it goes to approxidate_careful(), which accepts it without complaint as "now". The name then resolves to the current value of HEAD.

We only parse the whole string like this after peel_onion() has failed, so a peel that should fail succeeds with the wrong object:

    $ git rev-parse --verify 'HEAD@{1}^{/no-such-subject}'
    <object name of HEAD>

Only accept a selector whose "@{" is closed by the final '}'. Reflog selectors never contain a '}', so no valid selector is rejected.

Signed-off-by: Caspar Duregger <caspar.duregger@gmail.com>
---
 object-name.c              | 6 ++++++
 t/t1508-at-combinations.sh | 4 ++++
 2 files changed, 10 insertions(+)
diff --git a/object-name.c b/object-name.c
index 6546685760..13e4dc0f21 100644
--- a/object-name.c
+++ b/object-name.c
@@ -712,6 +712,12 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
 					nth_prior = 1;
 					continue;
 				}
+				/*
+				 * The final '}' must close this "@{", not a
+				 * later suffix as in "ref@{1}^{tree}".
+				 */
+				if (memchr(str + at + 2, '}', len - at - 3))
+					break;
 				if (!upstream_mark(str + at, len - at) &&
 				    !push_mark(str + at, len - at)) {
 					reflog_len = (len-1) - (at+2);
diff --git a/t/t1508-at-combinations.sh b/t/t1508-at-combinations.sh
index 87a4286414..10a8c3ad9d 100755
--- a/t/t1508-at-combinations.sh
+++ b/t/t1508-at-combinations.sh
@@ -84,6 +84,10 @@ nonsense "@{-1}@{-1}"
 check "HEAD@{3}" commit old-two
 nonsense "@{3}"
 
+# a failed peel must not be retried as a reflog date
+nonsense "HEAD@{1}^{blob}"
+nonsense "@{1}^{/no-such-subject}"
+
 test_expect_success 'switch to old-branch' '
 	git checkout old-branch
 '
-- 
2.56.1.windows.1
Previous: Caspar DureggerNext: Caspar Duregger
Message 5 of 8 in “cat-file: dies with --batch if reflog entry is out of bounds”
  1. Kristoffer HaugsbakkFeb 11, 2026
  2. Junio C HamanoFeb 11, 2026
  3. Jeff KingFeb 12, 2026
  4. 0/4 cat-file: do not die on reflog entries out of rangeCaspar Duregger, Nov 13, 2026
  5. 1/4 object-name: do not read a peel suffix as a reflog selectorCaspar Duregger, Nov 13, 2026
  6. 2/4 object-name: let GET_OID_GENTLY affect only failing lookupsCaspar Duregger, Nov 13, 2026
  7. 3/4 refs: let read_ref_at() fail gently on an empty reflogCaspar Duregger, Nov 13, 2026
  8. 4/4 cat-file: report out-of-range reflog entries as missingCaspar Duregger, Nov 13, 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.