[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