Skip to content

use size_t when parsing and checking objects

Elia Pinto git 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4object-file: use size_t in check_object_signature()object-file.c object-file.h+2 -20 replies
2/4fsck: use size_t for the size of objects to checkfsck.c fsck.h+12 -120 replies
3/4object, commit, tag: use size_t when parsing object bufferscommit.c commit.h object-file-convert.c +4 more+12 -120 replies
4/4tag, fmt-merge-msg, ref-filter: use size_t for message buffersfmt-merge-msg.c ref-filter.c tag.c+5 -50 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/4] use size_t when parsing and checking objects

This series continues the search for truncated sizes on platforms where "long" is 32 bits (Windows). It covers the functions that parse, verify, and check whole objects in memory: they take the size as an "unsigned long", while their callers have a size_t, so above 4GiB the size gets truncated.

Each patch addresses a specific component:
- 1/4: a valid object reported as corrupt;
- 2/4: fsck looks at only a prefix (e.g., .gitmodules);
- 3/4: parsing of a prefix (with set_commit_buffer() now dying instead of caching a truncated size, as repo_get_commit_buffer() already does);
- 4/4: "git tag -v" doesn't find the signature, plus the int index in copy_subject() on all platforms.

There are no out-of-bounds accesses; large objects only fail or are handled as if they were shorter.

No tests are added because they would need objects over 4GiB in memory, and they'd only detect the bug where long is 32 bits. I am happy to add EXPENSIVE tests guarded by !LONG_IS_64BIT (like t1051) if reviewers prefer.

Not covered here: the pack paths (index-pack, unpack-objects, pack verification) still pass an "unsigned long" to fsck_object(); that's the next series. The tree API (parse_tree_buffer(), init_tree_desc*()) is in the tree-walk series:
https://lore.kernel.org/git/[email protected]/
This series doesn't depend on the other series in flight and merges cleanly with them. Based on master 50fe5cc63f.

Elia Pinto (4):
object-file: use size_t in check_object_signature()
fsck: use size_t for the size of objects to check object, commit, tag: use size_t when parsing object buffers tag, fmt-merge-msg, ref-filter: use size_t for message buffers

 commit.c              |  8 ++++----
 commit.h              |  6 +++---
 fmt-merge-msg.c       |  2 +-
 fsck.c                | 18 +++++++++---------
 fsck.h                |  6 +++---
 object-file-convert.c |  2 +-
 object-file.c         |  2 +-
 object-file.h         |  2 +-
 object.c              |  2 +-
 object.h              |  2 +-
 ref-filter.c          |  6 +++---
 tag.c                 |  4 ++--
 tag.h                 |  2 +-
 13 files changed, 31 insertions(+), 31 deletions(-)

base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7

Signature · 1 line
2.53.0