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

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

From
AGAlessio Attilio via GitGitGadget <gitgitgadget@gmail.com>
Date
Dec 1, 2026, 18:49 UTC
Message-ID
<pull.2514.git.git.1796150994354.gitgitgadget@gmail.com>
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.

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

Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
---
    tree-walk: preserve large entry path lengths
    
    Tree entry path lengths are decoded into narrower integer types before
    the tree buffer has finished parsing them. Keep the decoded length as
    size_t so oversized paths are not truncated before tree walkers can
    reject them.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2514%2Fkairosci%2Ftopic%2Ftree-walk-pathlen-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2514/kairosci/topic/tree-walk-pathlen-v1
Pull-Request: https://github.com/git/git/pull/2514
 fsck.c      | 3 ++-
 tree-walk.c | 2 +-
 tree-walk.h | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/fsck.c b/fsck.c
index 94c8651c7d..9dbf7b6b0d 100644
--- a/fsck.c
+++ b/fsck.c
@@ -659,7 +659,8 @@ static int fsck_tree(const struct object_id *tree_oid,
 		has_dotdot |= !strcmp(name, "..");
 		has_dotgit |= is_hfs_dotgit(name) || is_ntfs_dotgit(name);
 		has_zero_pad |= *(char *)desc.buffer == '0';
-		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;
 
 		if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) {
 			if (!S_ISLNK(mode))
diff --git a/tree-walk.c b/tree-walk.c
index aaac1fd48d..e2b654232e 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -17,7 +17,7 @@
 static int decode_tree_entry(struct tree_desc *desc, const char *buf, size_t size, struct strbuf *err)
 {
 	const char *path;
-	unsigned int len;
+	size_t len;
 	uint16_t mode;
 	const unsigned hashsz = desc->algo->rawsz;
 
diff --git a/tree-walk.h b/tree-walk.h
index 5ccd4a9361..7c154e7ace 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -16,7 +16,7 @@ struct repository;
 struct name_entry {
 	struct object_id oid;
 	const char *path;
-	int pathlen;
+	size_t pathlen;
 	unsigned int mode;
 };
 
@@ -61,7 +61,7 @@ static inline const struct object_id *tree_entry_extract(struct tree_desc *desc,
  * memory structure of a tree entry to avoid the overhead of using a
  * generic strlen().
  */
-static inline int tree_entry_len(const struct name_entry *ne)
+static inline size_t tree_entry_len(const struct name_entry *ne)
 {
 	return ne->pathlen;
 }

base-commit: 566b6997dd4710b625c0882cf10a7443bf52d183
-- 
gitgitgadget
Next: Kristofer Karlsson
Message 1 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.