68 lines
2.3 KiB
Diff
68 lines
2.3 KiB
Diff
From 79baebe50e4d6b73ae1f8b603f0ef41300110aa3 Mon Sep 17 00:00:00 2001
|
|
From: Mark Adler <madler@alumni.caltech.edu>
|
|
Date: Sat, 13 Apr 2019 17:05:16 -0700
|
|
Subject: [PATCH] Avoid adding empty gzip member after gzflush with Z_FINISH.
|
|
|
|
Reference:https://github.com/madler/zlib/commit/79baebe50e4d6b73ae1f8b603f0ef41300110aa3
|
|
Conflict:NA
|
|
---
|
|
gzguts.h | 1 +
|
|
gzlib.c | 2 ++
|
|
gzwrite.c | 11 ++++++++++-
|
|
3 files changed, 13 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/gzguts.h b/gzguts.h
|
|
index 6378d468a..fc712dc4d 100644
|
|
--- 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 4838bf047..f6b3b406e 100644
|
|
--- 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 */
|
|
diff --git a/gzwrite.c b/gzwrite.c
|
|
index 52381332e..85b576ba3 100644
|
|
--- 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;
|