🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #4128

[PATCH] tree-walk: reject tree entries whose name length overflows an int

#4128
From: "Kristofer Karlsson via GitGitGa...
Date: Mon, 30 Nov 2026 14:42
94 lines
14170 bytes
From: Kristofer Karlsson <krka@spotify.com>

The EXPENSIVE tests 13-15 in t1600 have been failing in CI on all
64-bit platforms since 53d5cfc3b8 (tree-walk: use size_t for the size
of tree buffers, 2026-10-30) was merged:

  -fatal: index entry path is too long (4294967298 bytes)
  +fatal: malformed mode in tree entry

The tests were added in 89048b48fb (t1600-index: add expensive tests
for over-long tree paths, 2026-10-16).  They use a tree with a single
entry whose name is 2^32 - 2 bytes long.  decode_tree_entry() stores
that length in the "int" pathlen of struct name_entry, where it wraps
to -2.  update_tree_entry() then uses it to find the next entry, ends
up in the middle of the name, and fails to parse it.

Before 53d5cfc3b8 the tree size was truncated to 32 bits as well, so
the walk saw the 2^32 + 26 byte tree as 26 bytes.  That is exactly
what the wrapped entry length consumed, so the walk stopped without an
error and read-cache rejected the path as the tests expect.  Fixing
the tree size exposed the pathlen bug.

Fix this by keeping the name length in a size_t and rejecting names
longer than INT_MAX.  read-cache already has the same limit for index
entries, and index.maxPathLen cannot be set higher, so such names
could never be used anyway.  Update the tests to expect the new error.

Signed-off-by: Kristofer Karlsson <krka@spotify.com>
---
    tree-walk: reject tree entries whose name length overflows an int
    
    I ran into these t1600 failures in CI while working on something else.
    They started when ep/tree-walk-size-t was merged in "The 26th batch",
    and I could not find anyone working on a fix on the list, so here is
    one.
    
    Harald independently arrived at the same fix at the same time [1], but
    closed his PR in favor of this one.
    
    [1] https://github.com/git/git/pull/2512

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2342%2Fspkrka%2Ft1600-overlong-tree-fix-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2342/spkrka/t1600-overlong-tree-fix-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2342

 t/t1600-index.sh | 4 ++--
 tree-walk.c      | 7 ++++++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/t/t1600-index.sh b/t/t1600-index.sh
index dc4d68c1fb..b94e643e25 100755
--- a/t/t1600-index.sh
+++ b/t/t1600-index.sh
@@ -184,8 +184,8 @@ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,LONG_IS_64BIT \
 		git mktree >tree
 	) &&
 	overlong_tree=$(cat overlong/tree) &&
-	echo "fatal: index entry path is too long" \
-		"(4294967298 bytes)" >expect-overlong
+	echo "fatal: too long filename in tree entry" \
+		"(4294967294 bytes)" >expect-overlong
 '
 
 test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,LONG_IS_64BIT \
diff --git a/tree-walk.c b/tree-walk.c
index aaac1fd48d..f4b4d3fed7 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;
 
@@ -36,6 +36,11 @@ static int decode_tree_entry(struct tree_desc *desc, const char *buf, size_t siz
 		return -1;
 	}
 	len = strlen(path) + 1;
+	if (len - 1 > INT_MAX) {
+		strbuf_addf(err, _("too long filename in tree entry (%"PRIuMAX" bytes)"),
+			    (uintmax_t)(len - 1));
+		return -1;
+	}
 
 	/* Initialize the descriptor entry */
 	desc->entry.path = path;

base-commit: 86e79b2795e3ce3b0ad7685edd368574b0c8b9f2
-- 
gitgitgadget
Technical Details
Message-ID: <pull.2342.git.1796049772272.gitgitgadget@gmail.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76686-linux-kernel-git=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76686-linux-kernel-git=dewy.ru
From: gitgitgadget@gmail.com ("Kristofer Karlsson via GitGitGadget")
Newsgroups: linux.kernel.git
Subject: [PATCH] tree-walk: reject tree entries whose name length overflows an
 int
Date: Mon, 30 Nov 2026 14:42:52 +0000
Organization: Usenet Network
Message-ID: <pull.2342.git.1796049772272.gitgitgadget@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1447621"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:tu/lMdmoOt3B9+w2Bm9fWmz42Ek= sha256:XBtQsqiFqs+7Ued4XnGiBdwurda10n9ClsIlxuoI2Do=
	sha1:n7MfzsbVSahtWdwVrEbeh2k4Q9Q= sha256:DKJ/logg6sJCY8rsIiMRt9Q4UyqzCFsiwyhIO49BEcw=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 9F685125FED; Mon, 30 Nov 2026 17:43:09 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.049
X-Spam-Status: No, score=-1.049 tagged_above=-9999 required=6.31
	tests=[DCC_CHECK=1.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FORGED_GMAIL_RCVD=1,
	FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id sJZ1EC_WHXch;
	Mon, 30 Nov 2026 17:43:06 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=git+bounces-76686-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 19260125FEE; Mon, 30 Nov 2026 17:42:58 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id A89B960283E; Mon, 30 Nov 2026 14:42:57 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796049775;
	b=OixsfVCbJd3JVu28Eq9aYHpR4bNk9i1NNoGy/E1krrGkoI8ni+L3ePCaPFjOJvwz80tO
	 XKuwLtXaCBSLiBi1OMJ9NJzGb1HsqQtM6TpETWAO1x2jD2J+HoA4b24etEDUFfbJieef+
	 JehcONRbRP5nj3LJUWGuUSYbEdJGpZig5aSitGLNWgvXwGfWF/TstAcQC3XQL+8DyF2sw
	 NKZ66/R9+T+NzJv8J3Fw59TD2hPYbEYpcw4Sk5kQtPJYtSmWjOqSV99j8aCoVv0KgpCGJ
	 WHr46vRUuoQMpJm2u+VvjCU8waxnWUYrP5BCzfZvdmmEa8gfW8NzfZe47N7EkFavB6g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796049775;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:Message-Id:From:Date:Subject:Fcc:Content-Type:
	 Content-Transfer-Encoding:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:To:
	 Cc;
	bh=IMKESWroqq1d48ZpkIio34dRhGpvGRMOPoeAl6Sv7sw=;
	b=b4zX0n1TOhQsrS8L6PtLUJnt6IKitw2nB0E4TVmFD0r7olWqjN95NyDCgAiEaj06+w2I
	 yNiVbwtbIclAfjgR7Lz2fZkBmcCLyhr1aGjhlVn4H9L4SCcZzMzWNuDcHdZcZw6tNLtfn
	 YGU1Lg844lI82X3gHdnOiQXoMcWc1fEYYri9pauYjgMVebc0YUInBio/WIC9lI1T2r/uT
	 QcBGerCuv6R65Ktb5V5lzlx362yi0iOZQk/RbzaQUzD+DakL7BdRILqxMu7qVevhFaUmZ
	 w414AAuxmHSDrrwHp0lVeYshgpbOM4KJmSbOZdWlmwW2SG40iCdceDfgUQsU35QigBA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Z5qM8PA0;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 863DB606A32C;
	Mon, 30 Nov 2026 14:42:55 +0000 (UTC)
X-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=Z5qM8PA0
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.176
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796049774;
	b=YVqsx06fTQXXlNFrrNLaPzXxS7sy7YBBbEM5bm3EMPbc7VeW7YX4BW8W/V18KIFHydhe
	 QjOym5Y3rBcZSvULSlIvqGUT5aWa3E1TcNwv+GNpxWj3QAWGIGJjS4iiF8KjH/O/6evmK
	 atC20YAyTbIz6zRK45z3LhBAJUJzMQvmzs7LLDbV4jO1Hhz5/Tt70XCd2k3P+oD7tOna7
	 LwKMGSZ8F282OvqFdjYYpfffCGdrbS5RbF7m3/n102waanxLeZ6hUfKxEPMfzij5viexL
	 xISPKzdr61CljW/HlWg0NQtIj7oBRMR8AMrpc3jg/LRKHHB4oXpVm5L6MNBBq8xX8iQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796049774;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:From:Date:
	 Subject:Fcc:Content-Type:Content-Transfer-Encoding:MIME-Version:To:
	 Cc;
	bh=IMKESWroqq1d48ZpkIio34dRhGpvGRMOPoeAl6Sv7sw=;
	b=VuQoucWzhLK2rFLUlsGGrLjepRlxUOn1R6XZTi0atCUgReY+Cxtwh7jkcOKSMZu+yiNT
	 u9SUvfoYlqd1fJVxl08BglVjqmKUdGEMh8B05AVmRMp6z0gxujqPmFQ3flwYpHKI0Kmjw
	 eWKB8YvNheB2pECZO40VYV7z+UrChu9hwhCaQEhtjkWkbehKr5F3ZmtWAWmwEruMBFyd2
	 9KY98M43nKLe6h0hMEOvAAKKYZ4keG0Ndxtq4nCw5y7+tl6Gulit0fPhmC+1k/6K46Xxl
	 tv33AGpAENyp6kfGOKgkOA0IcNsvMNgSqibbA9uFQe/xhpHVB5A/mC1twyhkjNJajQA==
X-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=Z5qM8PA0;
	arc=none smtp.remote-ip=209.85.160.176
X-Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176])
	(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 50B9B606A31C
	for <git@vger.kernel.org>; Mon, 30 Nov 2026 14:42:54 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 50B9B606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-55db674106fso59465611cf.1
        for <git@vger.kernel.org>; Mon, 30 Nov 2026 06:42:54 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1796049773; x=1796654573; darn=vger.kernel.org;
        h=cc:to:mime-version:content-transfer-encoding:content-type:fcc
         :subject:date:from:message-id:from:to:cc:subject:date:message-id
         :reply-to:content-type;
        bh=IMKESWroqq1d48ZpkIio34dRhGpvGRMOPoeAl6Sv7sw=;
        b=Z5qM8PA0cJ6Jfa7Ei4TfiAL6hV5zh1ezDdVIvH/emi+V0mFTTOLOYmLpj9mn+veeTT
         RzCUdPlnUL64AsTdY8HJMzduUN8bzc6WwNlBzgWjePCtPVvimd1RNV/eDeQ627OCSQLN
         v0pFikQ2dAuDzJOAMhSMjXTRDOOPgl63uh7x6zS34CsXHBmR7JWPeCsxIo3b3fTp/DLd
         8RPYoNwtaiY9135uluYA3rECMlDEIxZUcdPfsQYL/p8oEXAlU9qfH/mvTh69fWlMwQki
         kDo0l4IgtBQjfExK9LroT/r/ZH3DKg6cVgMTBBikfJwSFUTeixewtymb1WcAeomIvcn0
         0cAA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1796049773; x=1796654573;
        h=cc:to:mime-version:content-transfer-encoding:content-type:fcc
         :subject:date:from:message-id:x-gm-gg:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to:content-type;
        bh=IMKESWroqq1d48ZpkIio34dRhGpvGRMOPoeAl6Sv7sw=;
        b=qgrBg9ggSUviqMz+SXWHdlP4BTVzyUYVjpFjPL1TZ6pek1et+7gNobtDGVh7rH6VtG
         HuRcmuiLrEcpK5pwEPJyo+e/ixa0DZ5LOuu2DlY7pEhsJQSFR5pKUDQ7ENMTJUshMKoA
         9/ko9LpGL0bplLzjUZTRQLRE2iniOaLiLhKJpm8rN7TAlRTLKVUp8yqtHQIa/eNgBzLO
         QCCDHAuDJBuwixN+Dq1yx8isrOZ0ZEOcTt7/UzqUCq28zAKjC7+pfMbtM2u+P+i5rgbu
         /KQ0eush6GVJACnfbO8ZL32lOparLTXpYNOpS/TudW4FjdBJfvJiz4RbZS+xsBdIJkBA
         D/Mg==
X-Gm-Message-State: APuU4Z+KPC3e8CuaEIUXEWokf4iIvnVFSvJiKdVn91rc8A7H7aX9IxzW
	pN2Jgy9rp1apzIkO+R621EYnyBiO+gVKXai6qtXmQp0vK2JS2BZVjITN+OcoSg==
X-Gm-Gg: AZFdTZfdevcGW3/KYPVdvQnrVzdoAogPuQ/uGw17nin+n4M0TF+fB37QkOAm6Vjdoj0
	ZYjst3IoryijnLAxktTf0CtF5+ykCmh0uO9dzZ/h2lFBUX8sWPdJJr/2cMXWWsEiq9MOG+o/rhx
	bIQSbS1u6GhpGGR+To0UtrQUPY8O0iMFLtRYMOEpLdxJo0xbdmDVS++9tJkKXatHqWDacOdypp5
	iAj/NxO8t7gqb+CkczqpTv6VpnbFIzOy+eW3p/JULWIojBI1w7dfcYZDKmvbfMgBjO7HLihU6pp
	ZGnh/iG2x5/DOgjk7Sn7YtkNv+ZYbFue6Ef2K500taZgQbDJSTtW6tokj6T91WkCg1tM1lyUgVp
	8gk58I8FZFi2b8RdoNZlKqdcdb8mXnTAFqRukFIW+sspGDNUq4yQNdVAlqj0yJt5UnkxgFcBveH
	IIM2PWfnsHi/OsnAwrLFoxZPLrLI1JDOqfzoW6jXgIIgSkgGgOqwKjPtBL4BJPAaktSLg2G7Z09
	Z8L1FyRpb9TNVceuFWYifGr/eU+YFPvhW6CN7d5jWgcOM+yZzplkvXSuVZtrEmNrrTnT1gqKC1p
	vMn7bfuITJhMl8FsTdphbYfWSA5Cnpsm
X-Received: by 2002:ac8:5fcf:0:b0:55c:6ef2:7103 with SMTP id d75a77b69052e-55d76a88271mr598745301cf.39.1796049773173;
        Mon, 30 Nov 2026 06:42:53 -0800 (PST)
X-Received: from [127.0.0.1] ([9.169.198.161])
        by smtp.gmail.com with ESMTPSA id d75a77b69052e-55dc7a6700csm109234461cf.7.2026.11.30.06.42.52
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 30 Nov 2026 06:42:52 -0800 (PST)
X-Fcc: Sent
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list
X-Cc: Elia Pinto <gitter.spiros@gmail.com>,
    Elijah Newren <newren@gmail.com>,
    Johannes Schindelin <johannes.schindelin@gmx.de>,
    Harald Nordgren <haraldnordgren@gmail.com>,
    Kristofer Karlsson <krka@spotify.com>,
    Kristofer Karlsson <krka@spotify.com>