]> git.ipfire.org Git - thirdparty/zlib-ng.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)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 22 Oct 2019 07:55:41 +0000 (09:55 +0200)
gzguts.h
gzlib.c
gzwrite.c

index 7389db8ab64166d8f6949a2074791d99d14a390a..066617fe9acd3e5c29934ca141461504148442a7 100644 (file)
--- 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 dbf27aa43e391253039e42521da517f474968518..56326ccc755e235ec3b0aefc838cb6709f6e306f 100644 (file)
--- 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 */
index 5b128055bfdb603e27dd76cf3cb93ee2523c2da0..b98022e621ec0b1f35440a9f9c8e7835ccb80791 100644 (file)
--- 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;
 }