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

Re: fatal error when diffing changed symlinks

From
Jeff King <peff@peff.net>
Date
Feb 24, 2017, 20:35 UTC
Message-ID
<20170224203523.mdoh4ivhwflmpr6j@sigill.intra.peff.net>
In-Reply-To
<xmqqtw7j1i6d.fsf@gitster.mtv.corp.google.com>
On Fri, Feb 24, 2017 at 11:51:22AM -0800, Junio C Hamano wrote:
Show 24 quoted lines
> > A slightly worse is that the upcoming Git will ship with a rewritten
> > "difftool" that makes the above sequence segfault.
> 
> The culprit seems to be these lines in run_dir_diff():
> 
> 		if (S_ISLNK(lmode)) {
> 			char *content = read_sha1_file(loid.hash, &type, &size);
> 			add_left_or_right(&symlinks2, src_path, content, 0);
> 			free(content);
> 		}
> 
> 		if (S_ISLNK(rmode)) {
> 			char *content = read_sha1_file(roid.hash, &type, &size);
> 			add_left_or_right(&symlinks2, dst_path, content, 1);
> 			free(content);
> 		}
> 
> When viewing a working tree file, oid.hash could be 0{40} and
> read_sha1_file() is not the right function to use to obtain the
> contents.
> 
> Both of these two need to pay attention to 0{40}, I think, as the
> user may be running "difftool -R --dir-diff" in which case the
> working tree would appear in the left hand side instead.

As a side note, I think even outside of 0{40}, this should be checking the return value of read_sha1_file(). A corrupted repo should die(), not segfault.

-Peff
Previous: Junio C HamanoNext: Johannes Schindelin
Message 4 of 17 in “fatal error when diffing changed symlinks”
  1. Christophe MacabiauFeb 24, 2017
  2. Junio C HamanoFeb 24, 2017
  3. Junio C HamanoFeb 24, 2017
  4. Jeff KingFeb 24, 2017
  5. Johannes SchindelinFeb 25, 2017
  6. Junio C HamanoMar 7, 2017
  7. Johannes SchindelinMar 7, 2017
  8. difftool: handle changing symlinks in dir-diff modeDavid Aguilar, Mar 13, 2017
  9. Junio C HamanoMar 13, 2017
  10. Johannes SchindelinMar 13, 2017
  11. Johannes SchindelinMar 13, 2017
  12. Junio C HamanoMar 13, 2017
  13. David AguilarMar 14, 2017
  14. Junio C HamanoMar 14, 2017
  15. Junio C HamanoMar 14, 2017
  16. Junio C HamanoMar 13, 2017
  17. Johannes SchindelinMar 13, 2017

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.