From: Junio C Hamano <gitster@pobox.com>
To: Han Young <hanyang.tony@bytedance.com>
Cc: git@vger.kernel.org
Subject: Re: [External] Re: [PATCH v2 1/1] diffcore-break: prevent dangling pointer
Date: Fri, 13 Feb 2026 09:16:32 -0800 [thread overview]
Message-ID: <xmqqwm0gmumn.fsf@gitster.g> (raw)
In-Reply-To: <CAG1j3zH0C0DA+V35A1e73wi41gmk9Xry6gmtZM3w3LT09etntQ@mail.gmail.com> (Han Young's message of "Fri, 13 Feb 2026 15:14:03 +0800")
Han Young <hanyang.tony@bytedance.com> writes:
>> 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.
next prev parent reply other threads:[~2026-02-13 17:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-11 4:11 [PATCH 0/1] diffcore-break: prevent dangling pointer Han Young
2026-02-11 4:11 ` [PATCH 1/1] " Han Young
2026-02-11 17:54 ` Junio C Hamano
2026-02-12 7:20 ` [PATCH v2 0/1] " Han Young
2026-02-12 7:20 ` [PATCH v2 1/1] " Han Young
2026-02-12 18:58 ` Junio C Hamano
2026-02-13 7:14 ` [External] " Han Young
2026-02-13 17:16 ` Junio C Hamano [this message]
2026-02-24 6:13 ` [PATCH v3 0/1] diffcore-break: avoid segfault with freed entries Han Young
2026-02-24 6:13 ` [PATCH v3 1/1] " Han Young
2026-02-24 15:22 ` [PATCH v3 0/1] " Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqwm0gmumn.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=hanyang.tony@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox