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

Re: [PATCH] tree-walk: preserve large entry path lengths

From
Kristofer Karlsson <krka@spotify.com>
Date
Dec 2, 2026, 13:43 UTC
Message-ID
<CAL71e4ORmUdsfd3doLGhykhHe=rqfzaYNpwkVinfBxuzUVsDdg@mail.gmail.com>
In-Reply-To
<pull.2514.git.git.1796150994354.gitgitgadget@gmail.com>

On Tue, 1 Dec 2026 at 19:49, Alessio Attilio via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 6 quoted lines
>
> From: Alessio Attilio <attilio.alessio@protonmail.com>
>
> The tree buffer uses size_t, but decoded entry lengths were still
> stored in unsigned int and int. A large path could therefore be
> truncated before tree walkers reached it.

This fixes the same CI failure in t1600 that I sent a patch for yesterday [1], but from the other direction: you keep the long name, while mine rejects names longer than INT32_MAX in decode_tree_entry().

The commit message could say more about how this broke. The t1600 tests started failing when 53d5cfc3b8 (tree-walk: use size_t for the size of tree buffers, 2026-10-30) stopped truncating the tree size, which used to hide the wrapped pathlen. Feel free to reuse parts of the explanation from my commit message if needed.

> Keep the decoded length as size_t so walkers can reject oversized
> index paths correctly.

I applied your patch and ran t1600 with --long, and tests 13-15 pass again without any test changes. t1450 also passes.

Show 5 quoted lines
> diff --git a/fsck.c b/fsck.c
> [...]
> -               has_large_name |= tree_entry_len(&desc.entry) > max_tree_entry_len;
> +               has_large_name |= max_tree_entry_len < 0 ||
> +                       tree_entry_len(&desc.entry) > (size_t)max_tree_entry_len;

Instead of the extra "< 0" check, how about turning max_tree_entry_len into a size_t and parsing it with git_parse_size_t()? It was an ssize_t only because tree_entry_len() used to return an int, and a negative limit does not make much sense anyway.

[snip]
> diff --git a/tree-walk.h b/tree-walk.h
> [...]
> -       int pathlen;
> +       size_t pathlen;

From reading the callers, most of the code that consumes pathlen already takes a size_t, so this looks correct to me. One exception I noticed is "int te_len = tree_entry_len(&entry)" in builtin/grep.c, which still narrows it to an int.

Patrick, thinking about this more, I believe this is a better fix than mine since it can avoid adding a new limit on path lengths. Platforms that cannot handle such a tree still fail, just earlier, when loading it.

This also matches how 0fbcaef6b4 (fsck: detect very large tree pathnames, 2023-08-31) dealt with very long names: instead of a hard limit when parsing trees, it added a configurable fsck check, which transfer.fsckObjects can use to keep such trees out.

For the documentation, rather than a hard maximum in gitdatamodel(7), it may then be better to say that names longer than 4096 bytes are not portable, which is what fsck.largePathname already warns about.

If you agree, I will drop my patch in favor of this one.
[1] https://lore.kernel.org/git/pull.2342.git.1796049772272.gitgitgadget@gmail.com/
Previous: Alessio Attilio via GitGitGadgetNext: ATTILIO ALESSIO
Message 2 of 5 in “tree-walk: preserve large entry path lengths”
  1. tree-walk: preserve large entry path lengthsAlessio Attilio via GitGitGadget, Dec 1, 2026
  2. Kristofer KarlssonDec 2, 2026
  3. ATTILIO ALESSIODec 2, 2026
  4. tree-walk: preserve large entry path lengthsAlessio Attilio via GitGitGadget, Dec 2, 2026
  5. Kristofer KarlssonDec 2, 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.