]> git.ipfire.org Git - thirdparty/git.git/commitdiff
packfile, git-zlib: widen `use_pack()` and zstream avail fields to `size_t`
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 9 Jul 2026 16:49:34 +0000 (16:49 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Jul 2026 21:55:24 +0000 (14:55 -0700)
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>
builtin/pack-objects.c
git-zlib.h
pack-check.c
packfile.c
packfile.h

index f739fee7532715e62f0a6dc77ad40879fa519346..bef1305ce47d00af89e421edbb4ade35ee19020d 100644 (file)
@@ -488,7 +488,7 @@ static void copy_pack_data(struct hashfile *f,
                off_t len)
 {
        unsigned char *in;
-       unsigned long avail;
+       size_t avail;
 
        while (len) {
                in = use_pack(p, w_curs, offset, &avail);
@@ -2260,7 +2260,7 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
                struct object_id base_ref;
                struct object_entry *base_entry;
                unsigned long used, used_0;
-               unsigned long avail;
+               size_t avail;
                off_t ofs;
                unsigned char *buf, c;
                enum object_type type;
@@ -2756,8 +2756,8 @@ size_t oe_get_size_slow(struct packing_data *pack,
        struct pack_window *w_curs;
        unsigned char *buf;
        enum object_type type;
-       unsigned long used, avail;
-       size_t size;
+       unsigned long used;
+       size_t avail, size;
 
        if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) {
                size_t sz;
index 44380e8ad3830563e249e75e46a52e0c4efcff77..0b24b15bd05f7f2adb0e5ab113bcf6b22e125316 100644 (file)
@@ -5,8 +5,8 @@
 
 typedef struct git_zstream {
        struct z_stream_s z;
-       unsigned long avail_in;
-       unsigned long avail_out;
+       size_t avail_in;
+       size_t avail_out;
        size_t total_in;
        size_t total_out;
        unsigned char *next_in;
index 5adfb3f2726fb3a4a02174f0c6e8157f64375c63..befb860472f418b92e63659802fa47ad53348349 100644 (file)
@@ -34,7 +34,7 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs,
        uint32_t data_crc = crc32(0, NULL, 0);
 
        do {
-               unsigned long avail;
+               size_t avail;
                void *data = use_pack(p, w_curs, offset, &avail);
                if (avail > len)
                        avail = len;
@@ -71,7 +71,7 @@ static int verify_packfile(struct repository *r,
 
        r->hash_algo->init_fn(&ctx);
        do {
-               unsigned long remaining;
+               size_t remaining;
                unsigned char *in = use_pack(p, w_curs, offset, &remaining);
                offset += remaining;
                if (!pack_sig_ofs)
index 78c389e6f35e220e0ed09d1d9c3afe7d03b1ead6..7fbe47ca18f86eb5f5f0e035ee09c4ef83257383 100644 (file)
@@ -704,7 +704,7 @@ static int in_window(struct repository *r, struct pack_window *win,
 unsigned char *use_pack(struct packed_git *p,
                struct pack_window **w_cursor,
                off_t offset,
-               unsigned long *left)
+               size_t *left)
 {
        struct pack_window *win = *w_cursor;
 
@@ -1228,7 +1228,7 @@ int unpack_object_header(struct packed_git *p,
                         size_t *sizep)
 {
        unsigned char *base;
-       unsigned long left;
+       size_t left;
        unsigned long used;
        enum object_type type;
 
index defb6f442cca09924bc135b770d95dc33bc078b2..820d247d054645c6f9026f8d4a8745429797680a 100644 (file)
@@ -402,7 +402,8 @@ uint32_t get_pack_fanout(struct packed_git *p, uint32_t value);
 
 struct object_database;
 
-unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
+unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t,
+                       size_t *);
 void close_pack_windows(struct packed_git *);
 void close_pack(struct packed_git *);
 void unuse_pack(struct pack_window **);