]> git.lizzy.rs Git - zlib.git/commitdiff
Avoid adding empty gzip member after gzflush with Z_FINISH.
authorMark Adler <madler@alumni.caltech.edu>
Sun, 14 Apr 2019 00:05:16 +0000 (17:05 -0700)
committerMark Adler <madler@alumni.caltech.edu>
Sun, 14 Apr 2019 00:08:50 +0000 (17:08 -0700)
gzguts.h
gzlib.c
gzwrite.c

index 6378d468a258b134420c2434f62de8f0d3fb42ea..fc712dc4d6fc6b8f2d36db01125ce76212c82534 100644 (file)
--- a/gzguts.h
+++ b/gzguts.h
@@ -190,6 +190,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 4838bf04745beb5722fa4c69436ccc9d3fae68fb..f6b3b406e64f75e1925998db8a747eb69d67fc48 100644 (file)
--- a/gzlib.c
+++ b/gzlib.c
@@ -81,6 +81,8 @@ local void gz_reset(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 */
index 52381332edd157fcfc553a786c11b0fd9bf2f0b8..85b576ba3053700bacf6bee047d08dd11f677ebf 100644 (file)
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -97,6 +97,15 @@ local int gz_comp(state, 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;
+        deflateReset(strm);
+        state->reset = 0;
+    }
+
     /* run deflate() on provided input until it produces no more output */
     ret = Z_OK;
     do {
@@ -134,7 +143,7 @@ local int gz_comp(state, flush)
 
     /* if that completed a deflate stream, allow another to start */
     if (flush == Z_FINISH)
-        deflateReset(strm);
+        state->reset = 1;
 
     /* all done, no errors */
     return 0;