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

Bug: combined diff with --ignore-matching-lines

From
René Scharfe <l.s.r@web.de>
Date
May 14, 2022, 09:32 UTC
Message-ID
<a6a14213-bc82-d6fb-43dd-5a423c40a4f8@web.de>
Hi all,

git diff segfaults when it's asked to produce a combined diff and ignore certain lines with --ignore-matching-lines/-I, e.g.:

   $ git diff -I DEF_VER v2.33.3 v2.33.3^@
   zsh: segmentation fault  ./git-diff -I DEF_VER v2.33.3 v2.33.3^@

That's because combine-diff.c::diff_tree_combined() copies a diffopt without making a deep copy of the ignore_regex array and frees it, then later tries to use it.

The segfault can be fixed by adding "diffopt.no_free = 1;" or reverting c45dc9cf30 (diff: plug memory leak from regcomp() on {log,diff} -I, 2021-02-11).

But even with that the only thing the command ignores is the option -I; the GIT-VERSION-GEN changes in the middle should have been omitted:

   $ git diff -I DEF_VER v2.33.3 v2.33.3^@
   diff --cc Documentation/RelNotes/2.33.3.txt
   index 0000000000,0000000000..e2bada12a1
   new file mode 100644
   --- /dev/null
   +++ b/Documentation/RelNotes/2.33.3.txt
   @@@ -1,0 -1,0 +1,4 @@@
   ++Git Documentation/RelNotes/2.33.3.txt Release Notes
   ++=========================
   ++
   ++This release merges up the fixes that appear in v2.33.3.
   diff --cc GIT-VERSION-GEN
   index d81eab5f00,e7efe58866..86a3a2870c
   --- a/GIT-VERSION-GEN
   +++ b/GIT-VERSION-GEN
   @@@ -1,7 -1,7 +1,7 @@@
     #!/bin/sh
     GVF=GIT-VERSION-FILE
   - DEF_VER=v2.33.2
    -DEF_VER=v2.32.2
   ++DEF_VER=v2.33.3
     LF='
     '
   diff --cc RelNotes
   index 8e79de2efe,4ac68388c3..899139d9ec
   --- a/RelNotes
   +++ b/RelNotes
   @@@ -1,1 -1,1 +1,1 @@@
   - Documentation/RelNotes/2.33.2.txt
    -Documentation/RelNotes/2.32.2.txt
   ++Documentation/RelNotes/2.33.3.txt
Just setting need_generic_pathscan is not enough.  Ideas?
René
Next: Ævar Arnfjörð Bjarmason
Message 1 of 12 in “Bug: combined diff with --ignore-matching-lines”
  1. René ScharfeMay 14, 2022
  2. diff: fix a segfault in >2 tree -I<regex> and --output=<file>Ævar Arnfjörð Bjarmason, May 23, 2022
  3. Junio C HamanoMay 23, 2022
  4. Ævar Arnfjörð BjarmasonMay 24, 2022
  5. Junio C HamanoMay 24, 2022
  6. Ævar Arnfjörð BjarmasonMay 24, 2022
  7. René ScharfeJun 18, 2022
  8. 1/2 combine-diff: abort if --ignore-matching-lines is givenRené Scharfe, Jun 18, 2022
  9. Junio C HamanoJun 21, 2022
  10. René ScharfeJun 21, 2022
  11. Junio C HamanoJun 21, 2022
  12. 2/2 combine-diff: abort if --output is givenRené Scharfe, Jun 18, 2022

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.