Commit 51c7cd2 for zlib
commit 51c7cd2cc6d3a0c6a22ac336f9168c719bc13cb6
Author: M0nd0R <150439604+M0nd0R@users.noreply.github.com>
Date: Mon Oct 5 16:35:10 2026 +0000
Discard unconsumed zero fill in gz_zero() on a write error.
If gz_comp() stalled on a write to a non-blocking destination before
consuming any of the current zero-fill chunk, that chunk is left in the
input buffer with state->skip not yet reduced for it. On the retry, the
leading gz_comp() in gz_zero() consumes those leftovers, but that path
performs no skip accounting -- correct for the user data it was written
for, wrong for pending zero fill. The do-loop then generates a fresh
chunk against the same skip, and the output ends up with an extra
state->size zero bytes that the application never wrote.
Discard the unconsumed remainder on the error return so that the retry
regenerates it, mirroring the input-pointer reset gz_write() performs
when it returns on a non-blocking stall.
diff --git a/gzwrite.c b/gzwrite.c
index 3052259..f3343a0 100644
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -175,8 +175,14 @@ local int gz_zero(gz_statep state) {
n -= strm->avail_in;
state->x.pos += n;
state->skip -= n;
- if (ret == -1)
+ if (ret == -1) {
+ /* discard any unconsumed zero fill -- it was not yet accounted
+ for in state->skip, so it will be generated again when the
+ operation is retried */
+ strm->avail_in = 0;
+ strm->next_in = state->in;
return -1;
+ }
} while (state->skip);
return 0;
}