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

[PATCH v2 0/1] Avoid segmentation fault in git range-diff when diff.noprefix=true

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 2, 2019, 21:10 UTC
Message-ID
<pull.373.v2.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.373.git.gitgitgadget@gmail.com>

This PR was inspired by this bug report: https://public-inbox.org/git/20191002141615.GB17916@kitsune.suse.cz/T/#me576615d7a151cf2ed46186c482fbd88f9959914

Changes since v1:
 * Use a command-line option instead of a command-line config setting.
 * Instead of forcing a prefix, force no prefix (and adjust the strip
   level).
 * Fix typo "all" -> "call" in the commit message (and adjust it to reflect
   the other changes since v1, too).
Johannes Schindelin (1):
  range-diff: internally force `diff.noprefix=true`
 range-diff.c          | 3 ++-
 t/t3206-range-diff.sh | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)
base-commit: bc12974a897308fd3254cf0cc90319078fe45eea
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-373%2Fdscho%2Frange-diff-requires-diff-prefix-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-373/dscho/range-diff-requires-diff-prefix-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/373
Range-diff vs v1:
 1:  1f84f92846 ! 1:  9993a607be range-diff: internally force `diff.noprefix=false`
     @@ -1,6 +1,6 @@
      Author: Johannes Schindelin <johannes.schindelin@gmx.de>
      
     -    range-diff: internally force `diff.noprefix=false`
     +    range-diff: internally force `diff.noprefix=true`
      
          When parsing the diffs, `range-diff` expects to see the prefixes `a/`
          and `b/` in the diff headers.
     @@ -9,25 +9,33 @@
          `diff.noprefix=true`. As `range-diff` is not prepared for that
          situation, this will cause a segmentation fault.
      
     -    Let's avoid that by forcing `diff.noprefix=false` just for that all to
     -    `git log` that generates the diffs that `range-diff` wants to parse.
     +    Let's avoid that by passing the `--no-prefix` option to the `git log`
     +    process that generates the diffs that `range-diff` wants to parse.
     +    And of course expect the output to have no prefixes, then.
      
     -    Noticed-by: Michal Suchánek <msuchanek@suse.de>
     +    Reported-by: Michal Suchánek <msuchanek@suse.de>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       diff --git a/range-diff.c b/range-diff.c
       --- a/range-diff.c
       +++ b/range-diff.c
      @@
     - 	int offset, len;
     - 	size_t size;
       
     --	argv_array_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
     -+	argv_array_pushl(&cp.args, "-c", "diff.noprefix=false",
     -+			"log", "--no-color", "-p", "--no-merges",
     + 	argv_array_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
       			"--reverse", "--date-order", "--decorate=no",
     ++			"--no-prefix",
       			/*
       			 * Choose indicators that are not used anywhere
     + 			 * else in diffs, but still look reasonable
     +@@
     + 			if (!util->diff_offset)
     + 				util->diff_offset = buf.len;
     + 			line[len - 1] = '\n';
     +-			len = parse_git_diff_header(&root, &linenr, 1, line,
     ++			len = parse_git_diff_header(&root, &linenr, 0, line,
     + 						    len, size, &patch);
     + 			if (len < 0)
     + 				die(_("could not parse git header '%.*s'"), (int)len, line);
      
       diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh
       --- a/t/t3206-range-diff.sh
-- 
gitgitgadget
Previous: Junio C HamanoNext: Johannes Schindelin via GitGitGadget
Message 9 of 11 in “Avoid segmentation fault in git range-diff when diff.noprefix=true”
  1. 0/1 Avoid segmentation fault in git range-diff when diff.noprefix=trueJohannes Schindelin via GitGitGadget, Oct 2, 2019
  2. 1/1 range-diff: internally force `diff.noprefix=false`Johannes Schindelin via GitGitGadget, Oct 2, 2019
  3. Eric SunshineOct 2, 2019
  4. Michal SuchánekOct 2, 2019
  5. Junio C HamanoOct 2, 2019
  6. Johannes SchindelinOct 2, 2019
  7. Junio C HamanoOct 3, 2019
  8. Junio C HamanoOct 3, 2019
  9. 0/1 Avoid segmentation fault in git range-diff when diff.noprefix=trueJohannes Schindelin via GitGitGadget, Oct 2, 2019
  10. 1/1 range-diff: internally force `diff.noprefix=true`Johannes Schindelin via GitGitGadget, Oct 2, 2019
  11. Junio C HamanoOct 3, 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.