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

Re: [External] Re: [PATCH v2 1/1] diffcore-break: prevent dangling pointer

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 13, 2026, 17:16 UTC
Message-ID
<xmqqwm0gmumn.fsf@gitster.g>
In-Reply-To
<CAG1j3zH0C0DA+V35A1e73wi41gmk9Xry6gmtZM3w3LT09etntQ@mail.gmail.com>
Han Young <hanyang.tony@bytedance.com> writes:
Show 32 quoted lines
>> Your "do not leave q->queue[] dangling, as other people may still
>> look at them" fix certainly is a good hygiene, but I have to wonder
>> why we are doing break detection in this case in the first place.
>> For the internal "Let's figure out which path have changed, so that
>> we re-read only those changed paths" invocation of diff machinery,
>> we should not be doing so.  A break detection is to see if the
>> change in the contents of a single path is a total rewrite, and
>> regardless of the answer, the fact that the path was modified does
>> not change, update_index_from_diff() would work on the path anyway.
>> I also suspect that, if we are doing rename detection in this call
>> to do_diff_cache(), it is a totally wasted effort.  We may want to
>> take a deeper look at it, possibly outside the theme of this more
>> focused fix.
>
> I'm not familiar with reset and diff machinery; I encountered this bug
> during a real world mixed reset. The segmentfault calling stack is
> cmd_reset -> read_from_tree -> diffcore_std -> diffcore_break
> It looks like rename detection is indeed pointless.
>
>> By the way, I find it highly curious that with the following patch
>> to revert the fix with a bit of extra output sprinkled to your
>> tests, the problem does not reproduce reliably, which may indicate
>> that your test may be flaky (i.e., timing dependent).  Am I doing
>> something bogus in the patch?
>
> It seems the problem does not reproduce reliably with or without your
> patch. I suspect that could be due to the freed memory on some
> occasions isn't reused by system, thus the access later on doesn't
> trigger a segment fault. On my macOS system, the test passes around
> 5% of the time. However, if I set q->queue[i] to a bogus memory
> location like 0x1 causes a Git segment fault every time.
> Is there a better way to write tests for this kind of situation?

If it is flaky because it depends on the way the system allocator happens to reuse or not reuse a piece of memory, as long as we do not get hit by false positives, it would be OK to leave it as-is if we do not find a good solution, because running tests under asan would catch such problems, I think.

Thanks.
Previous: Han YoungNext: Han Young
Message 8 of 11 in “diffcore-break: prevent dangling pointer”
  1. 0/1 diffcore-break: prevent dangling pointerHan Young, Feb 11, 2026
  2. 1/1 diffcore-break: prevent dangling pointerHan Young, Feb 11, 2026
  3. Junio C HamanoFeb 11, 2026
  4. 0/1 diffcore-break: prevent dangling pointerHan Young, Feb 12, 2026
  5. 1/1 diffcore-break: prevent dangling pointerHan Young, Feb 12, 2026
  6. Junio C HamanoFeb 12, 2026
  7. Han YoungFeb 13, 2026
  8. Junio C HamanoFeb 13, 2026
  9. 0/1 diffcore-break: avoid segfault with freed entriesHan Young, Feb 24, 2026
  10. 1/1 diffcore-break: avoid segfault with freed entriesHan Young, Feb 24, 2026
  11. Junio C HamanoFeb 24, 2026

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.