packfile, git-zlib: widen `use_pack()` and zstream avail fields to `size_t`

Bundling the two widenings: four call sites pass `&stream.avail_in` directly to `use_pack()`, and widening either type fencepost alone would force a bridge variable at each. Doing both together is the simpler end state and is the prerequisite for the `do_compress()` widening in the next commit, which is what lets `write_no_reuse_object()` lose its last `cast_size_t_to_ulong()` shim. The unsigned-long locals widened at the other `use_pack()` callers (avail / remaining / left) hold pack-window sizes bounded by `core.packedGitWindowSize`, so the change is type consistency rather than a new >4GB capability. `git_zstream.avail_in`/`avail_out` likewise reach zlib's `uInt` fields only after `zlib_buf_cap()`'s 1 GiB cap, so the wrapper already accepted `size_t`-shaped inputs in practice. Assisted-by: Opus 4.7 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jul 9, 2026 at 16:49 UTC 9647dcedd7749e675d585d32d7ea34f2b8c90a38
5 files changed +12 -11
builtin/pack-objects.c
+4 -4
@@ -488,7 +488,7 @@ static void copy_pack_data(struct hashfile *f,
488 off_t len)
489 {
490 unsigned char *in;
491 - unsigned long avail;
491 + size_t avail;
492
493 while (len) {
494 in = use_pack(p, w_curs, offset, &avail);
@@ -2260,7 +2260,7 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
2260 struct object_id base_ref;
2261 struct object_entry *base_entry;
2262 unsigned long used, used_0;
2263 - unsigned long avail;
2263 + size_t avail;
2264 off_t ofs;
2265 unsigned char *buf, c;
2266 enum object_type type;
@@ -2756,8 +2756,8 @@ size_t oe_get_size_slow(struct packing_data *pack,
2756 struct pack_window *w_curs;
2757 unsigned char *buf;
2758 enum object_type type;
2759 - unsigned long used, avail;
2760 - size_t size;
2759 + unsigned long used;
2760 + size_t avail, size;
2761
2762 if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) {
2763 size_t sz;
git-zlib.h
+2 -2
@@ -5,8 +5,8 @@
5
6 typedef struct git_zstream {
7 struct z_stream_s z;
8 - unsigned long avail_in;
9 - unsigned long avail_out;
8 + size_t avail_in;
9 + size_t avail_out;
10 size_t total_in;
11 size_t total_out;
12 unsigned char *next_in;
pack-check.c
+2 -2
@@ -34,7 +34,7 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs,
34 uint32_t data_crc = crc32(0, NULL, 0);
35
36 do {
37 - unsigned long avail;
37 + size_t avail;
38 void *data = use_pack(p, w_curs, offset, &avail);
39 if (avail > len)
40 avail = len;
@@ -71,7 +71,7 @@ static int verify_packfile(struct repository *r,
71
72 r->hash_algo->init_fn(&ctx);
73 do {
74 - unsigned long remaining;
74 + size_t remaining;
75 unsigned char *in = use_pack(p, w_curs, offset, &remaining);
76 offset += remaining;
77 if (!pack_sig_ofs)
packfile.c
+2 -2
@@ -704,7 +704,7 @@ static int in_window(struct repository *r, struct pack_window *win,
704 unsigned char *use_pack(struct packed_git *p,
705 struct pack_window **w_cursor,
706 off_t offset,
707 - unsigned long *left)
707 + size_t *left)
708 {
709 struct pack_window *win = *w_cursor;
710
@@ -1228,7 +1228,7 @@ int unpack_object_header(struct packed_git *p,
1228 size_t *sizep)
1229 {
1230 unsigned char *base;
1231 - unsigned long left;
1231 + size_t left;
1232 unsigned long used;
1233 enum object_type type;
1234
packfile.h
+2 -1
@@ -402,7 +402,8 @@ uint32_t get_pack_fanout(struct packed_git *p, uint32_t value);
402
403 struct object_database;
404
405 -unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
405 +unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t,
406 + size_t *);
407 void close_pack_windows(struct packed_git *);
408 void close_pack(struct packed_git *);
409 void unuse_pack(struct pack_window **);