From: Mark Adler Date: Sun, 14 Apr 2019 00:05:16 +0000 (-0700) Subject: Avoid adding empty gzip member after gzflush with Z_FINISH. X-Git-Tag: 1.9.9-b1~401 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72c9ed141529150513f30ce3a15db03f2fd066d4;p=thirdparty%2Fzlib-ng.git Avoid adding empty gzip member after gzflush with Z_FINISH. --- diff --git a/gzguts.h b/gzguts.h index 7389db8a..066617fe 100644 --- a/gzguts.h +++ b/gzguts.h @@ -139,6 +139,7 @@ typedef struct { /* just for writing */ int level; /* compression level */ int strategy; /* compression strategy */ + int reset; /* true if a reset is pending after a Z_FINISH */ /* seek request */ z_off64_t skip; /* amount to skip (already rewound if backwards) */ int seek; /* true if seek request pending */ diff --git a/gzlib.c b/gzlib.c index dbf27aa4..56326ccc 100644 --- a/gzlib.c +++ b/gzlib.c @@ -28,6 +28,8 @@ static void gz_reset(gz_state *state) { state->past = 0; /* have not read past end yet */ state->how = LOOK; /* look for gzip header */ } + else /* for writing ... */ + state->reset = 0; /* no deflateReset pending */ state->seek = 0; /* no seek request pending */ gz_error(state, Z_OK, NULL); /* clear error */ state->x.pos = 0; /* no uncompressed data yet */ diff --git a/gzwrite.c b/gzwrite.c index 5b128055..b98022e6 100644 --- a/gzwrite.c +++ b/gzwrite.c @@ -91,6 +91,15 @@ static int gz_comp(gz_state *state, int flush) { return 0; } + /* check for a pending reset */ + if (state->reset) { + /* don't start a new gzip member unless there is data to write */ + if (strm->avail_in == 0) + return 0; + PREFIX(deflateReset)(strm); + state->reset = 0; + } + /* run deflate() on provided input until it produces no more output */ ret = Z_OK; do { @@ -122,8 +131,7 @@ static int gz_comp(gz_state *state, int flush) { /* if that completed a deflate stream, allow another to start */ if (flush == Z_FINISH) - PREFIX(deflateReset)(strm); - + state->reset = 1; /* all done, no errors */ return 0; }