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

Re: [BUG] diffcore-rename with duplicate tree entries can segfault

From
Jeff King <peff@peff.net>
Date
Feb 24, 2015, 22:49 UTC
Message-ID
<20150224224918.GA24749@peff.net>
In-Reply-To
<xmqqh9uborrx.fsf@gitster.dls.corp.google.com>
On Tue, Feb 24, 2015 at 02:42:42PM -0800, Junio C Hamano wrote:
Show 12 quoted lines
> > That does fix this problem, and it doesn't break any other tests. But
> > frankly, I don't know what I'm doing and this feels like a giant hack.
> >
> > Given that this is tangentially related to the "-B -M" stuff you've been
> > looking at (and it's your code in the first place :) ), I thought you
> > might have some insight.
> 
> Indeed.
> 
> Honestly, I'd rather see us diagnose duplicate filepairs as an error
> and drop them on the floor upon entry to the diffcore_std(), even
> before we go into the rename codepath.

Yeah, I had a similar thought. Just saying "your diff is broken, we can't do rename detection" is totally reasonable to me.

My main concern with that approach is that we would waste time finding the duplicate paths, for something that comes up only rarely. At the time of locate_rename_dst, we've already created a mapping, and it's very easy to detect the duplicates. But before that, we have only the linear list of queued items.

In theory they're sorted and we could do an O(n) pass to find duplicates. But I'm not sure if the sorting holds in the face of other breakages (like unsorted trees; they also shouldn't happen, but the whole point here is to gracefully handle things that shouldn't).

I dunno. Maybe we could do an O(n) pass to check sort order and uniqueness. If either fails (which should be rare), then we sort and re-check uniqueness.

I'm assuming there _is_ a sane sort order. We have two halves of a filepair, but I think before any of the rename or break detection kicks in, each pair should either:

  1. Have a name in pair->one, and an invalid filespec in pair->two
     (i.e., a deletion).
  2. The opposite (name in pair->two, /dev/null in pair->one). An
     addition.
  3. The same name in pair->one and pair->two.
-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 12 in “[BUG] diffcore-rename with duplicate tree entries can segfault”
  1. Jeff KingFeb 24, 2015
  2. Junio C HamanoFeb 24, 2015
  3. Jeff KingFeb 24, 2015
  4. Junio C HamanoFeb 24, 2015
  5. Jeff KingFeb 24, 2015
  6. Junio C HamanoFeb 25, 2015
  7. Jeff KingFeb 25, 2015
  8. Junio C HamanoFeb 25, 2015
  9. 0/2 diffcore-rename with duplicate tree entries can segfaultJeff King, Feb 27, 2015
  10. 1/2 diffcore-rename: split locate_rename_dst into two functionsJeff King, Feb 27, 2015
  11. 2/2 diffcore-rename: avoid processing duplicate destinationsJeff King, Feb 27, 2015
  12. Junio C HamanoFeb 27, 2015

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.