diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2019-04-13 17:05:16 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2019-04-13 17:08:50 -0700 |
commit | 79baebe50e4d6b73ae1f8b603f0ef41300110aa3 (patch) | |
tree | ce453518c642755fafd819d8e36ba0b79ceff069 | |
parent | 0e96d8e7c7079ab9f07cc7b57ae3ca9de8c80742 (diff) | |
download | zlib-79baebe50e4d6b73ae1f8b603f0ef41300110aa3.tar.gz zlib-79baebe50e4d6b73ae1f8b603f0ef41300110aa3.tar.bz2 zlib-79baebe50e4d6b73ae1f8b603f0ef41300110aa3.zip |
Avoid adding empty gzip member after gzflush with Z_FINISH.
-rw-r--r-- | gzguts.h | 1 | ||||
-rw-r--r-- | gzlib.c | 2 | ||||
-rw-r--r-- | gzwrite.c | 11 |
3 files changed, 13 insertions, 1 deletions
@@ -190,6 +190,7 @@ typedef struct { | |||
190 | /* just for writing */ | 190 | /* just for writing */ |
191 | int level; /* compression level */ | 191 | int level; /* compression level */ |
192 | int strategy; /* compression strategy */ | 192 | int strategy; /* compression strategy */ |
193 | int reset; /* true if a reset is pending after a Z_FINISH */ | ||
193 | /* seek request */ | 194 | /* seek request */ |
194 | z_off64_t skip; /* amount to skip (already rewound if backwards) */ | 195 | z_off64_t skip; /* amount to skip (already rewound if backwards) */ |
195 | int seek; /* true if seek request pending */ | 196 | int seek; /* true if seek request pending */ |
@@ -81,6 +81,8 @@ local void gz_reset(state) | |||
81 | state->past = 0; /* have not read past end yet */ | 81 | state->past = 0; /* have not read past end yet */ |
82 | state->how = LOOK; /* look for gzip header */ | 82 | state->how = LOOK; /* look for gzip header */ |
83 | } | 83 | } |
84 | else /* for writing ... */ | ||
85 | state->reset = 0; /* no deflateReset pending */ | ||
84 | state->seek = 0; /* no seek request pending */ | 86 | state->seek = 0; /* no seek request pending */ |
85 | gz_error(state, Z_OK, NULL); /* clear error */ | 87 | gz_error(state, Z_OK, NULL); /* clear error */ |
86 | state->x.pos = 0; /* no uncompressed data yet */ | 88 | state->x.pos = 0; /* no uncompressed data yet */ |
@@ -97,6 +97,15 @@ local int gz_comp(state, flush) | |||
97 | return 0; | 97 | return 0; |
98 | } | 98 | } |
99 | 99 | ||
100 | /* check for a pending reset */ | ||
101 | if (state->reset) { | ||
102 | /* don't start a new gzip member unless there is data to write */ | ||
103 | if (strm->avail_in == 0) | ||
104 | return 0; | ||
105 | deflateReset(strm); | ||
106 | state->reset = 0; | ||
107 | } | ||
108 | |||
100 | /* run deflate() on provided input until it produces no more output */ | 109 | /* run deflate() on provided input until it produces no more output */ |
101 | ret = Z_OK; | 110 | ret = Z_OK; |
102 | do { | 111 | do { |
@@ -134,7 +143,7 @@ local int gz_comp(state, flush) | |||
134 | 143 | ||
135 | /* if that completed a deflate stream, allow another to start */ | 144 | /* if that completed a deflate stream, allow another to start */ |
136 | if (flush == Z_FINISH) | 145 | if (flush == Z_FINISH) |
137 | deflateReset(strm); | 146 | state->reset = 1; |
138 | 147 | ||
139 | /* all done, no errors */ | 148 | /* all done, no errors */ |
140 | return 0; | 149 | return 0; |