From: Junio C Hamano <gitster@pobox.com>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org, ps@pks.im
Subject: Re: [PATCH v2] refs/ref-cache: fix SEGFAULT when seeking in empty directories
Date: Fri, 26 Sep 2025 09:30:50 -0700 [thread overview]
Message-ID: <xmqq5xd5ch1h.fsf@gitster.g> (raw)
In-Reply-To: <CAOLa=ZSfL1CVCNjD0Vi3kpQqLM6t7YVa=G2ChGpaza6WOjZTCw@mail.gmail.com> (Karthik Nayak's message of "Fri, 26 Sep 2025 03:41:58 -0400")
Karthik Nayak <karthik.188@gmail.com> writes:
> This wouldn't happen because before the loop starts, we set:
>
> dir = get_ref_dir(iter->cache->root);
>
> So, `dir` will always have an entry (i.e. 'refs') in the first
> iteration, after that, the checks in the while section of the 'do {}
> while (...)' loop will kick in.
Ah, OK. So we know dir->nr != 0 when the loop is entered for the
first time. We may descend into a new subdirectory and at that
point we might hit dir->nr == 0 and that is why we want to catch it
at the end of "do {} while ()". Makes sense.
>> I wonder if we can leave at
>> the beginning of the outer loop, even before sort_ref_dir(dir), when
>> dir->nr is zero, or something?
>
> We could add it there too. I can't see the merit of one over the other.
No, I don't, either. As long as we know dir->nr != 0 upon the entry
into the loop, the check at the tail end in while() is sufficient.
Thanks for clarifying. I wonder if a bit of update to the log
message would help future readers of the code, though.
When using the files-backend with packed-refs, it is possible that some
of the refs directories are empty. For e.g. just after repacking, the
'refs/heads' directory would be empty. The ref-cache seek mechanism,
doesn't take this into consideration when descending into a subdirectory,
and makes an out of bounds access, causing SEGFAULT as we try to
access entries within the directory. Fix this by breaking out of the
loop when we enter an empty directory.
or something? I dunno.
Thanks.
next prev parent reply other threads:[~2025-09-26 16:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-24 7:55 [PATCH] refs/ref-cache: stop seeking into empty directories Karthik Nayak
2025-09-24 12:28 ` Patrick Steinhardt
2025-09-25 8:20 ` Karthik Nayak
2025-09-25 9:15 ` [PATCH v2] refs/ref-cache: fix SEGFAULT when seeking in " Karthik Nayak
2025-09-25 17:07 ` Junio C Hamano
2025-09-26 7:41 ` Karthik Nayak
2025-09-26 7:44 ` Karthik Nayak
2025-09-26 16:30 ` Junio C Hamano [this message]
2025-09-29 14:47 ` Karthik Nayak
2025-10-01 12:17 ` [PATCH v3] " Karthik Nayak
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=xmqq5xd5ch1h.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
--cc=ps@pks.im \
/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;
as well as URLs for NNTP newsgroup(s).