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

Re: [PATCH] diff --no-index: fix logic for paths ending in '/'

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 24, 2025, 22:03 UTC
Message-ID
<xmqqecrvjyoi.fsf@gitster.g>
In-Reply-To
<20250924-jk-fix-no-index-path-with-slash-v1-1-6b2028c0de92@intel.com>
Jacob Keller <jacob.e.keller@intel.com> writes:
Show 17 quoted lines
> If one of the two provided paths for git diff --no-index ends in a '/',
> a failure similar to the following occurs:
>
>   $ git diff --no-index -- /tmp/ /tmp/ ':!'
>   fatal: `pos + len' is too far after the end of the buffer
>
> This occurs because of an incorrect calculation of the skip lengths in
> diff_no_index(). The code wants to calculate the length of the string,
> but add one in case the string doesn't end with a slash.
>
> The method it uses is incorrect, as it always checks the trailing NUL
> character of the string. This will never be a '/', so we always add one.
> In the event that we *do* have a trailing slash, this will create an
> off-by-one length error later when using the skip value.
>
> The most straightforward fix would be to correct the skip1 and skip2
> lengths by using ends_with().

Meaning, "ah, this one ends with '/' so let's trim it and do everything else the same as before"?

It certainly is how we usually handle regression fixes.

There were two topics that touched "git diff --no-index" in Git 2.51 timeframe, and the pathspec support was a new feature added by them, so this is not exactly a regression.

> This fix might feel overly complex. We can drop this and just go with a
> simple ends_with() fix, but that leaves the needless strbuf_remove() in the
> read_directory_contents.

We can do it as a two-step patch series, which would allow us to revert the more complex part relatively cleanly if it turns out to break the cases that the current code handles fine. But as this is a new feature in 2.51, it is OK to declare that the code never worked correctly and we are making it right this time with a single more ambitious patch.

Will queue.  Thanks, both of you.
Previous: Jacob KellerNext: Junio C Hamano
Message 2 of 8 in “diff --no-index: fix logic for paths ending in '/'”
  1. diff --no-index: fix logic for paths ending in '/'Jacob Keller, Sep 24, 2025
  2. Junio C HamanoSep 24, 2025
  3. Junio C HamanoSep 24, 2025
  4. Junio C HamanoSep 24, 2025
  5. Jacob KellerSep 25, 2025
  6. Junio C HamanoSep 25, 2025
  7. Junio C HamanoOct 10, 2025
  8. Jacob KellerOct 13, 2025

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.