git/oss-fuzz
Johannes Schindelin 606c192380 odb, packfile: use size_t for streaming object sizes
The odb_read_stream structure uses unsigned long for the size field,
which is 32-bit on Windows even in 64-bit builds. When streaming
objects larger than 4GB, the size would be truncated to zero or an
incorrect value, resulting in empty files being written to disk.

Change the size field in odb_read_stream to size_t and introduce
unpack_object_header_sz() to return sizes via size_t pointer. Since
object_info.sizep remains unsigned long for API compatibility, use
temporary variables where the types differ, with comments noting the
truncation limitation for code paths that still use unsigned long.

Widening the producers to size_t in this way introduces a handful of
silent size_t -> unsigned long narrowings on Windows, all in
builtin/pack-objects.c, where the consumers are still typed
unsigned long. Make those narrowings explicit with
cast_size_t_to_ulong() so they assert loudly the moment an object
actually exceeds ULONG_MAX bytes:

  - oe_get_size_slow() returns unsigned long but holds a size_t
    locally; cast at the return.
  - write_reuse_object() passes a size_t into check_pack_inflate(),
    whose expect parameter is unsigned long; cast at the call.
  - check_object() routes a size_t through SET_SIZE() and
    SET_DELTA_SIZE(), both of which take unsigned long via
    oe_set_size() / oe_set_delta_size(); cast at the three call
    sites in the OBJ_OFS_DELTA / OBJ_REF_DELTA branches and in the
    non-delta default arm.

The cast-only treatment is deliberately a stop-gap. Properly
widening oe_set_size, oe_get_size_slow's return type,
check_pack_inflate's expect parameter, object_info.sizep,
patch_delta, and the OE_SIZE_BITS bit-fields cascades into a series
that is too large to be reviewable, so the proper widening is
deferred to a follow-up topic. Until then,
cast_size_t_to_ulong() at least makes the truncation explicit at
the source: it documents the boundary, and on a 64-bit non-Windows
platform it is a no-op.

This was originally authored by LordKiRon <https://github.com/LordKiRon>,
who preferred not to reveal their real name and therefore agreed that I
take over authorship.

Helped-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-05-09 11:25:31 +09:00
..
.gitignore fuzz: port fuzz-url-decode-mem from OSS-Fuzz 2024-10-16 18:14:11 -04:00
dummy-cmd-main.c oss-fuzz: mark unused argv/argc argument 2024-08-17 09:46:11 -07:00
fuzz-commit-graph.c environment: stop storing `core.attributesFile` globally 2026-02-17 12:09:42 -08:00
fuzz-config.c fuzz: add fuzzer for config parsing 2024-03-15 10:47:05 -07:00
fuzz-credential-from-url-gently.c fuzz: port fuzz-credential-from-url-gently from OSS-Fuzz 2024-10-16 18:14:11 -04:00
fuzz-date.c date: make DATE_MODE thread-safe 2024-04-05 15:21:14 -07:00
fuzz-pack-headers.c odb, packfile: use size_t for streaming object sizes 2026-05-09 11:25:31 +09:00
fuzz-pack-idx.c object-store: rename files to "odb.{c,h}" 2025-07-01 14:46:34 -07:00
fuzz-parse-attr-line.c Merge branch 'ps/the-repository' 2025-01-21 08:44:54 -08:00
fuzz-url-decode-mem.c fuzz: port fuzz-url-decode-mem from OSS-Fuzz 2024-10-16 18:14:11 -04:00
meson.build meson: simplify use of the common-main library 2025-02-26 09:09:35 -08:00