Merge branch 'js/objects-larger-than-4gb-on-windows' into next

A hotfix to an earlier attempt to update code paths that assumed
"unsigned long" was long enough for "size_t".

* js/objects-larger-than-4gb-on-windows:
  zlib: properly clamp to uLong
Junio C Hamano 2026-06-18 11:32:07 -07:00
commit 99d7cf9126
1 changed files with 9 additions and 4 deletions

View File

@ -38,12 +38,17 @@ static inline uInt zlib_buf_cap(unsigned long len)
return (ZLIB_BUF_MAX < len) ? ZLIB_BUF_MAX : len;
}

static inline uLong zlib_uLong_cap(size_t s)
{
return s < ULONG_MAX_VALUE ? (uLong)s : ULONG_MAX_VALUE;
}

static void zlib_pre_call(git_zstream *s)
{
s->z.next_in = s->next_in;
s->z.next_out = s->next_out;
s->z.total_in = (uLong)(s->total_in & ULONG_MAX_VALUE);
s->z.total_out = (uLong)(s->total_out & ULONG_MAX_VALUE);
s->z.total_in = zlib_uLong_cap(s->total_in);
s->z.total_out = zlib_uLong_cap(s->total_out);
s->z.avail_in = zlib_buf_cap(s->avail_in);
s->z.avail_out = zlib_buf_cap(s->avail_out);
}
@ -60,7 +65,7 @@ static void zlib_post_call(git_zstream *s, int status)
* We track our own totals and verify only the low bits match.
*/
if ((s->z.total_out & ULONG_MAX_VALUE) !=
((s->total_out + bytes_produced) & ULONG_MAX_VALUE))
((zlib_uLong_cap(s->total_out) + bytes_produced) & ULONG_MAX_VALUE))
BUG("total_out mismatch");
/*
* zlib does not update total_in when it returns Z_NEED_DICT,
@ -68,7 +73,7 @@ static void zlib_post_call(git_zstream *s, int status)
*/
if (status != Z_NEED_DICT &&
(s->z.total_in & ULONG_MAX_VALUE) !=
((s->total_in + bytes_consumed) & ULONG_MAX_VALUE))
((zlib_uLong_cap(s->total_in) + bytes_consumed) & ULONG_MAX_VALUE))
BUG("total_in mismatch");

s->total_out += bytes_produced;