Skip to content

Commit c62ab51

Browse files
committed
zlib: properly clamp to uLong
On platforms where `unsigned long` and `size_t` differ in bit size, we want to clamp the buffers we pass to zlib to the former's size, as per d05d666 (git-zlib: handle data streams larger than 4GB, 2026-05-08). The logic introduced in that commit performs a clamping to the bits, though, which fails to do what is needed here: If too many bytes are available in the buffers, we need to clamp to the maximum value of an `unsigned long`. Otherwise, we ask zlib to use too small buffers, in the worst case using 0 as the size (think: a value whose 32 lowest bits are all zero). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 7a094d6 commit c62ab51

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

git-zlib.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ static void zlib_pre_call(git_zstream *s)
4242
{
4343
s->z.next_in = s->next_in;
4444
s->z.next_out = s->next_out;
45-
s->z.total_in = (uLong)(s->total_in & ULONG_MAX_VALUE);
46-
s->z.total_out = (uLong)(s->total_out & ULONG_MAX_VALUE);
45+
s->z.total_in = (uLong)(s->total_in < ULONG_MAX_VALUE ?
46+
s->total_in : ULONG_MAX_VALUE);
47+
s->z.total_out = (uLong)(s->total_out < ULONG_MAX_VALUE ?
48+
s->total_out : ULONG_MAX_VALUE);
4749
s->z.avail_in = zlib_buf_cap(s->avail_in);
4850
s->z.avail_out = zlib_buf_cap(s->avail_out);
4951
}

0 commit comments

Comments
 (0)