From: Kristofer Karlsson Date: Wed, 02 Dec 2026 13:43:44 GMT Subject: Re: [PATCH] tree-walk: preserve large entry path lengths Message-ID: In-Reply-To: On Tue, 1 Dec 2026 at 19:49, Alessio Attilio via GitGitGadget wrote: > > From: Alessio Attilio > > 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. > 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/