From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.176 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== 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== 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 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 ; Mon, 30 Nov 2026 14:42:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 50B9B606A31C 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=Z5qM8PA0 Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-55db674106fso59465611cf.1 for ; Mon, 30 Nov 2026 06:42:54 -0800 (PST) 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) 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) Message-Id: From: "Kristofer Karlsson via GitGitGadget" Date: Mon, 30 Nov 2026 14:42:52 +0000 Subject: [PATCH] tree-walk: reject tree entries whose name length overflows an int 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: Elia Pinto , Elijah Newren , Johannes Schindelin , Harald Nordgren , Kristofer Karlsson , Kristofer Karlsson From: Kristofer Karlsson 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 --- 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