Skip to content

Commit

Permalink
lib-compress: Don't assume too early that gz file continues after a t…
Browse files Browse the repository at this point in the history
…railer.

Some istreams don't have EOF immediately set after the gz trailer. This
fixes errors like "missing gz trailer at 1675"
  • Loading branch information
sirainen committed Oct 25, 2016
1 parent ae052ae commit 5ea724b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lib-compression/istream-zlib.c
Expand Up @@ -36,6 +36,7 @@ struct zlib_istream {
unsigned int header_read:1;
unsigned int trailer_read:1;
unsigned int zs_closed:1;
unsigned int starting_concated_output:1;
};

static void i_stream_zlib_init(struct zlib_istream *zstream);
Expand Down Expand Up @@ -188,12 +189,31 @@ static ssize_t i_stream_zlib_read(struct istream_private *stream)
stream->istream.eof = TRUE;
return -1;
}
zstream->starting_concated_output = TRUE;
}
if (zstream->starting_concated_output) {
/* make sure there actually is something in parent stream.
we don't want to reset the stream unless we actually see
some concated output. */
ret = i_stream_read_more(stream->parent, &data, &size);
if (ret <= 0) {
if (ret == 0)
return 0;
if (stream->parent->stream_errno != 0) {
stream->istream.stream_errno =
stream->parent->stream_errno;
}
stream->istream.eof = TRUE;
return -1;
}

/* gzip file with concatenated content */
zstream->eof_offset = (uoff_t)-1;
zstream->stream_size = (uoff_t)-1;
zstream->header_read = FALSE;
zstream->trailer_read = FALSE;
zstream->crc32 = 0;
zstream->starting_concated_output = FALSE;

(void)inflateEnd(&zstream->zs);
i_stream_zlib_init(zstream);
Expand Down

0 comments on commit 5ea724b

Please sign in to comment.