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

[PATCH 1/2] rev-parse: demonstrate overflow of N for "foo^N" and "foo~N"

From
René Scharfe <l.s.r@web.de>
Date
Sep 15, 2019, 12:03 UTC
Message-ID
<c43610f2-a51f-7333-a200-a76930a0b705@web.de>

If the number gets too high for an int, weird things may happen, as signed overflows are undefined. Add a test to show this; rev-parse "sucessfully" interprets 100000000000000000000000000000000 to be the same as 0, at least on x64 with GCC 9.2.1 and Clang 8.0.1, which is obviously bogus.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 t/t1506-rev-parse-diagnosis.sh | 8 ++++++++
 1 file changed, 8 insertions(+)
diff --git a/t/t1506-rev-parse-diagnosis.sh b/t/t1506-rev-parse-diagnosis.sh
index 4ee009da66..5c4df47401 100755
--- a/t/t1506-rev-parse-diagnosis.sh
+++ b/t/t1506-rev-parse-diagnosis.sh
@@ -215,4 +215,12 @@ test_expect_success 'arg before dashdash must be a revision (ambiguous)' '
 	test_cmp expect actual
 '

+test_expect_failure 'reject Nth parent if N is too high' '
+	test_must_fail git rev-parse HEAD^100000000000000000000000000000000
+'
+
+test_expect_failure 'reject Nth ancestor if N is too high' '
+	test_must_fail git rev-parse HEAD~100000000000000000000000000000000
+'
+
 test_done
--
2.23.0
Next: René Scharfe
Message 1 of 4 in “rev-parse: demonstrate overflow of N for "foo^N" and "foo~N"”
  1. 1/2 rev-parse: demonstrate overflow of N for "foo^N" and "foo~N"René Scharfe, Sep 15, 2019
  2. 2/2 sha1-name: check for overflow of N in "foo^N" and "foo~N"René Scharfe, Sep 15, 2019
  3. brian m. carlsonSep 15, 2019
  4. René ScharfeSep 15, 2019

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.