"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
"Todd C. Miller" <Todd.Miller@sudo.ws>
Subject:
Re: reuse deltas while packing
To:
Stefan Sperling <stsp@stsp.name>
Cc:
Christian Weisgerber <naddy@mips.inka.de>, gameoftrees@openbsd.org
Date:
Mon, 07 Feb 2022 08:26:38 -0700

Download raw body.

Thread
On Mon, 07 Feb 2022 15:32:10 +0100, Stefan Sperling wrote:

> This patch fixes got-index-pack getting stuck.
>
> Unfortunately, zlib uses an unsigned int to represent the number of
> input bytes available in its input buffer, instead of a size_t.
>
> Large mapped files can cause truncation during our assignment from
> size_t to unsigned int when we update zlib's input length counter.
> This results in z->avail_in being set to zero, even though plenty
> of bytes are available for zlib to consume. We then loop forever
> asking zlib to decompress another zero bytes during every iteration.

Since the problem occurs when len - *consumed > UINT_MAX wouldn't
something like this be a little better?

	const size_t avail = len - *consumed;
	z->avail_in = MIN(avail, UINT_MAX);

That way the entire UINT_MAX is available.  Or if you prefer the
if() style:

	if (len - *consumed > UINT_MAX)
		z->avail_in = UINT_MAX;
	else
		z->avail_in = len - *consumed;

There should be no need to cast UINT_MAX to size_t since it is
explicitly unsigned and should be implicitly promoted to size_t for
the comparison.

 - todd