From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796221517; b=M86ndbP6GzwuXwMnBE34b1ZGQUQ1Sc1Yi4FKeHd0h0SeJhfRpHlOqMo7N0RoUyVXVVkL X9AKkVq28/zEf5V7qi2B9ZCPeUS+q21xhBjF8a+gKcKpwZbOvZB8blETZIsDxBoQNncCb 6UW+imIqS8y1AKs/+qlUcGZn1VS2UsD0D1WP0vJAA3rotPzoJI53611QOly1yMFgwwCk5 2gmtiL0ekEdkmMfV9/nJifhQjbpuUclsIFySTMrct/9C08eZhMRagJ7GGI767UaqRvxF1 xFWUHaEZahyFJlV+XsaFa1/Bd188kUed0e/OV4LFRE6ssvaM21o2h++j9b+EyLyfKrQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221517; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:In-Reply-To: References:From:Date:Subject:Fcc:Content-Type: Content-Transfer-Encoding:MIME-Version:To:Cc; bh=b+M7p3VLfeK8XG9RRmsSvwyBBOD3h1I52HVFdlWTXYk=; b=v6JAugdmVodlIWuI5jknKaTPDL4rR1+kl6/nu7wXgLwfTyO0f8lewDZGu658gNHxVUe0 Pddbloq0HrAWm75abaLGEy2KiRhxA4bts7naRmXP3u6u9/tkbvw+xXhFpGgkN0++oDFIi PQ92iZH3a7VAjeigNl+nle6u6ez7bnTrYGZ4cRoewXV9mU9tvylspkLkNVdc1AcCN1jEV NXeAHzRBogE+28rbpn8lBxfdFB8J2t4S9qZu45yBpIF5eX4RRnD9nwmjSGkoVZpaVvNZq gasMaZFEjDih+BnhVcOiapE8e2YaRJO/labLB4TUeP+C8Xzkzgl/KlEe73cCUk93o3g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=fvP4TjuH; arc=none smtp.remote-ip=209.85.214.169 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E67D606A322 for ; Wed, 2 Dec 2026 14:25:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8E67D606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=fvP4TjuH Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2f0464dd6b6so80387815ad.1 for ; Wed, 02 Dec 2026 06:25:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796221516; x=1796826316; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=b+M7p3VLfeK8XG9RRmsSvwyBBOD3h1I52HVFdlWTXYk=; b=fvP4TjuHbfEBYobEkvWM58HIpCum2uB6+OeckkQNJPcpQyL688X5bdZ5/X/PmW8VyA YvmAjYopai54vzA5tNcjxo+BGhnouy7tsC6KnU32OG8E2YtPKUiVUUlnRhmWjSpx1tbk IBwo6lkZs49rwIXebqoXgrBWbEMeIKaDXQFI47a0BAXahj905XI4sczgAkJLLF6i0XkW 57WzATvvjT/RUKk6C9Boo2qR59Q5xGP9/6lF7DXuENPL02I9QtHq0FNmjLDLudgiBHF8 1kzsZl8oDv2UEauczSShlmlf2dcN7g0LZWrcu045SkaWvI9lTJGbd0ILVXFWdC1SDM3c Uw6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796221516; x=1796826316; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=b+M7p3VLfeK8XG9RRmsSvwyBBOD3h1I52HVFdlWTXYk=; b=n9IY4znzmyz/M2Au4cMelGcvi+2iyl6xnor12+H+kthihWaAfJFhmjeOp6nuzJwQpF 1IcWXatxPBTWDnJm8p1tiMAN1xIVoY62zn7K48uXPS3NDOdrVxcJeJGW+YRcJlLNPCka DkxfKLm/99VwUMmKHxYDdlTWzC388K+uoaH1PHiIRoHXka2d4AfKYS+wVysBoIsGpVwY yZIsTlbMhXaSwYC1rqcpJ3/t8aK2MU8Wf41HmdpGVPQk2+8vUmuszwnKbwRiQAtLfwt8 uLjHQezddyJsHqmOO+57mXjnsK2QJCiEDuHnsBhaaLy8O6oor5DM7DL1dctFbvXR/LLN U5Tw== X-Gm-Message-State: APuU4Z/0/GJUi7DOm2zHo1IZKUzYdHLdUUhV80wYpBkbNYhghknXT6t0 IYVI0Fa5Z+BkSvKHxOJac+Xn6qCG/ahcgR1AxBmmeg9O6FdOOVb6cCBjV3sEdw== X-Gm-Gg: AZFdTZfje1p8eSNWWQ9+l/Oji3Fg8vOa/joxwrmn1B/EssZSZuA6DJBlBViIqVccaVd P0snItQL9AP/Sb9GWVfjl8tHeAeErjarvGGLf3tYdRqM/m6LhABTaq/9T+y1ZQ2WRX89ZZ4WObh 2obfUsHnqhsIWVGMgMZ4E6+ITw4SoKaaokFiZAoPLc+h7X2qnx2tGtwL/zLTO06WgYsKE36rPVw n42VcjFK8XYT8VH3yO+pqUZgChR/cmYlDGyM1cgcyOUkmtS28/VnHqqdRRKhrmLvGWYKmynkrqz WCCZnS/w5v/4gDHGlN9Dg5QU9kULKFuqwLaB/j8KMrDz7z1IzEGUUWb+EOAXuPjxrhi8trz5Bok DU/HDXni4DV6G2UnM8MSDp0q/pmi5ssNia94Fm3cKcZe5Wp836PHz6VUzu0qsLepZfN/GdKFv/D fVvwV/UdmweAOFCkugQdb4fROS0YIEze6kNmdQMg9Y6DKreG6hdPYHME3EsHgonVw0XzZ7hrM/M D5QJMha1YV9eHtMwHgdYTBUx+S1V69nL2TGf5yOZUjon8DPP9sITN6ODT9CIBDjVBgSH6L469Sj Rf9gLKrdd1kFE4yFviQRwids3vkbybYLtv7j5xkDPkjB1h3fJbF0Xz/Z X-Received: by 2002:a17:902:db11:b0:2e5:54c6:e5c9 with SMTP id d9443c01a7336-2f03ef870c8mr427853195ad.2.1796221515567; Wed, 02 Dec 2026 06:25:15 -0800 (PST) Received: from [127.0.0.1] ([172.171.103.158]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f162738c93sm32489765ad.43.2026.12.02.06.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 06:25:14 -0800 (PST) Message-Id: In-Reply-To: References: From: "Alessio Attilio via GitGitGadget" Date: Wed, 02 Dec 2026 14:25:14 +0000 Subject: [PATCH v2] tree-walk: preserve large entry path lengths Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 To: git@vger.kernel.org Cc: Kristofer Karlsson , Alessio Attilio , Alessio Attilio From: Alessio Attilio Tree entry path lengths were stored in unsigned int and int even though tree buffers are sized with size_t. This truncated paths larger than those types can represent. This became visible after 53d5cfc3b8 (tree-walk: use size_t for the size of tree buffers, 2026-10-30) stopped truncating the tree size: walkers could reach the full entry, but its path length had already wrapped. In particular, index path length checks then saw the wrong length, causing t1600 tests 13-15 to fail with --long. Keep the decoded length as size_t throughout tree-walk, including its callers, so the walkers can correctly handle or reject large paths. Document that names longer than 4096 bytes are not portable, while leaving rejection of such trees to the configurable fsck check. Signed-off-by: Alessio Attilio --- 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. Changes since v1: * Explain that 53d5cfc3b8 (tree-walk: use size_t for the size of tree buffers, 2026-10-30) stopped truncating the tree size, exposing the wrapped path length and causing t1600.13-15 to fail with --long. * Parse the fsck.largePathname limit as size_t with git_parse_size_t(). * Preserve the entry length as size_t in builtin/grep.c. * Document that names longer than 4096 bytes are not portable. Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2514%2Fkairosci%2Ftopic%2Ftree-walk-pathlen-v2 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2514/kairosci/topic/tree-walk-pathlen-v2 Pull-Request: https://github.com/git/git/pull/2514 Range-diff vs v1: 1: 6df3340782 ! 1: f59137c9c8 tree-walk: preserve large entry path lengths @@ Metadata ## Commit message ## tree-walk: preserve large entry path lengths - 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. + Tree entry path lengths were stored in unsigned int and int even + though tree buffers are sized with size_t. This truncated paths larger + than those types can represent. - Keep the decoded length as size_t so walkers can reject oversized - index paths correctly. + This became visible after 53d5cfc3b8 (tree-walk: use size_t for the + size of tree buffers, 2026-10-30) stopped truncating the tree size: + walkers could reach the full entry, but its path length had already + wrapped. In particular, index path length checks then saw the wrong + length, causing t1600 tests 13-15 to fail with --long. + + Keep the decoded length as size_t throughout tree-walk, including its + callers, so the walkers can correctly handle or reject large paths. + Document that names longer than 4096 bytes are not portable, while + leaving rejection of such trees to the configurable fsck check. Signed-off-by: Alessio Attilio + ## Documentation/gitdatamodel.adoc ## +@@ Documentation/gitdatamodel.adoc: tree:: + It can contain files or other trees (which are subdirectories). + It lists, for each item in the tree: + + +-1. The *filename*, for example `hello.py` ++1. The *filename*, for example `hello.py`. Names longer than 4096 bytes ++ are not portable across all systems. + 2. The *file type*, which must be one of these five types: + - *regular file* + - *executable file* + + ## builtin/grep.c ## +@@ builtin/grep.c: static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, + } + + while (tree_entry(tree, &entry)) { +- int te_len = tree_entry_len(&entry); ++ size_t te_len = tree_entry_len(&entry); + + if (match != all_entries_interesting) { + strbuf_addstr(&name, base->buf + tn_len); + ## fsck.c ## -@@ fsck.c: 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; +@@ + #include "config.h" + #include "help.h" + +-static ssize_t max_tree_entry_len = 4096; ++static size_t max_tree_entry_len = 4096; - if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) { - if (!S_ISLNK(mode)) + #define STR(x) #x + #define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type }, +@@ fsck.c: void fsck_set_msg_type(struct fsck_options *options, + msg_type_str = to_free = + xmemdupz(msg_type_str, colon - msg_type_str); + colon++; +- if (!git_parse_ssize_t(colon, &max_tree_entry_len)) ++ if (!git_parse_size_t(colon, &max_tree_entry_len)) + die("unable to parse max tree entry len: %s", colon); + } + } ## tree-walk.c ## @@ Documentation/gitdatamodel.adoc | 3 ++- builtin/grep.c | 2 +- fsck.c | 4 ++-- tree-walk.c | 2 +- tree-walk.h | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Documentation/gitdatamodel.adoc b/Documentation/gitdatamodel.adoc index 056b866f25..f10617d729 100644 --- a/Documentation/gitdatamodel.adoc +++ b/Documentation/gitdatamodel.adoc @@ -85,7 +85,8 @@ tree:: It can contain files or other trees (which are subdirectories). It lists, for each item in the tree: + -1. The *filename*, for example `hello.py` +1. The *filename*, for example `hello.py`. Names longer than 4096 bytes + are not portable across all systems. 2. The *file type*, which must be one of these five types: - *regular file* - *executable file* diff --git a/builtin/grep.c b/builtin/grep.c index 22f0a1b0d0..c056312f06 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -627,7 +627,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, } while (tree_entry(tree, &entry)) { - int te_len = tree_entry_len(&entry); + size_t te_len = tree_entry_len(&entry); if (match != all_entries_interesting) { strbuf_addstr(&name, base->buf + tn_len); diff --git a/fsck.c b/fsck.c index 94c8651c7d..8f68112b6d 100644 --- a/fsck.c +++ b/fsck.c @@ -23,7 +23,7 @@ #include "config.h" #include "help.h" -static ssize_t max_tree_entry_len = 4096; +static size_t max_tree_entry_len = 4096; #define STR(x) #x #define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type }, @@ -167,7 +167,7 @@ void fsck_set_msg_type(struct fsck_options *options, msg_type_str = to_free = xmemdupz(msg_type_str, colon - msg_type_str); colon++; - if (!git_parse_ssize_t(colon, &max_tree_entry_len)) + if (!git_parse_size_t(colon, &max_tree_entry_len)) die("unable to parse max tree entry len: %s", colon); } } 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