Subject: Re: [PATCH 04/10] unpack_loose_header(): fix infinite loop on broken zlib input

From: Junio C Hamano <[email-masked]>
Date: Wed, 26 Feb 2025 04:56:04 -0800

Jeff King <[email-masked]> writes:

> diff --git a/object-file.c b/object-file.c
> index 8c9295413b..5b2446bfc1 100644
> --- a/object-file.c
> +++ b/object-file.c
> @@ -1396,7 +1396,7 @@ enum unpack_loose_header_result unpack_loose_header(git_zstream *stream,
>  		strbuf_add(header, buffer, stream->next_out - (unsigned char *)buffer);
>  		if (memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer))
>  			return 0;
> -	} while (status != Z_STREAM_END);
> +	} while (status == Z_OK);
>  	return ULHR_BAD;
>  }

Ah, fond memories.  I do recall we had very similar bugs whose
correct solution was "instead of stopping with Z_something, just
write your loop to keep ging while you get Z_OK" every time we
encountered them.