From ec63cd60eb08454cb02795b7535206876b9ef96e Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Sun, 20 Sep 2026 20:24:20 -0700 Subject: [PATCH] Fix one more truncated stream detection bug. This fixes a false negative that has been there since 1.2.4. --- gzread.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gzread.c b/gzread.c index 1a9af4dd..5641b3cc 100644 --- a/gzread.c +++ b/gzread.c @@ -302,8 +302,11 @@ local int gz_skip(gz_statep state) { } /* output buffer empty -- return if we're at the end of the input */ - else if (state->eof && state->strm.avail_in == 0) + else if (state->eof && state->strm.avail_in == 0) { + if (state->how == GZIP && state->err == Z_OK) + gz_error(state, Z_BUF_ERROR, "unexpected end of file"); break; + } /* need more data to skip -- load up output buffer */ else { @@ -356,8 +359,11 @@ local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len) { } /* output buffer empty -- return if we're at the end of the input */ - else if (state->eof && state->strm.avail_in == 0) + else if (state->eof && state->strm.avail_in == 0) { + if (state->how == GZIP && state->err == Z_OK) + gz_error(state, Z_BUF_ERROR, "unexpected end of file"); break; + } /* need output data -- for small len or new stream load up our output buffer, so that gzgetc() can be fast */