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

[PATCH 0/2] tree-walk: use size_t for tree sizes

From
Elia Pinto <gitter.spiros@gmail.com>
Date
Oct 30, 2026, 10:58 UTC
Message-ID
<cover.1793357680.git.gitter.spiros@gmail.com>

struct tree_desc keeps the size of the tree buffer in an "unsigned int", so a tree object of 4GiB or more is truncated on all platforms, and struct tree adds another truncation on Windows, where "long" is 32 bits. The walk then sees only a prefix of the tree: it never reads past the buffer, but when the cut falls between two entries the rest of the tree silently disappears, both for commands like "git ls-tree" and for the checks in fsck_tree().

Trees that large are not something one creates by accident, but they can be crafted, and fsck is what is supposed to look at every entry of them.

 1/2 moves struct tree_desc and the functions that set it up to
     size_t; this is the part that matters on all platforms.
 2/2 does the same for struct tree and parse_tree_buffer().

There is no test, as it would need a tree larger than 4GiB in memory; 1/2 describes how I checked the effect with a simulated 16-bit size.

This comes from the same search for truncated sizes as:
  https://lore.kernel.org/git/cover.1793352943.git.gitter.spiros@gmail.com/
  https://lore.kernel.org/git/cover.1793355390.git.gitter.spiros@gmail.com/

It is independent of both and merges cleanly with them. The series is based on master (b9e5cff180).

Elia Pinto (2):
  tree-walk: use size_t for the size of tree buffers
  tree: use size_t for the size of parsed trees
 tree-walk.c | 14 +++++++-------
 tree-walk.h |  6 +++---
 tree.c      |  2 +-
 tree.h      |  4 ++--
 4 files changed, 13 insertions(+), 13 deletions(-)
base-commit: b9e5cff1803ab24582201ef059516eb16014b9d9
-- 
2.53.0
Next: Elia Pinto
Message 1 of 6 in “tree-walk: use size_t for tree sizes”
  1. 0/2 tree-walk: use size_t for tree sizesElia Pinto, Oct 30, 2026
  2. 1/2 tree-walk: use size_t for the size of tree buffersElia Pinto, Oct 30, 2026
  3. Junio C HamanoNov 18, 2026
  4. 2/2 tree: use size_t for the size of parsed treesElia Pinto, Oct 30, 2026
  5. Junio C HamanoNov 18, 2026
  6. Elia PintoNov 17, 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.