diff options
| author | Junio C Hamano <gitster@pobox.com> | 2025-08-07 08:14:38 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-08-07 08:14:38 -0700 |
| commit | 94c3b34d9de0603fb69fc539b653288e9bd91edf (patch) | |
| tree | 2878e0b8a44be615a945b7af88903bfe003fe41f | |
| parent | Merge branch 'dl/squelch-maybe-uninitialized' (diff) | |
| parent | archive: flush deflate stream until Z_STREAM_END (diff) | |
| download | git-94c3b34d9de0603fb69fc539b653288e9bd91edf.tar.gz git-94c3b34d9de0603fb69fc539b653288e9bd91edf.zip | |
Merge branch 'jt/archive-zip-deflate-fix'
The deflate codepath in "git archive --format=zip" had a
longstanding bug coming from misuse of zlib API, which has been
corrected.
* jt/archive-zip-deflate-fix:
archive: flush deflate stream until Z_STREAM_END
Diffstat (limited to '')
| -rw-r--r-- | archive-zip.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/archive-zip.c b/archive-zip.c index dbd90d9c3d..bea5bdd43d 100644 --- a/archive-zip.c +++ b/archive-zip.c @@ -492,14 +492,22 @@ static int write_zip_entry(struct archiver_args *args, zstream.next_in = buf; zstream.avail_in = 0; - result = git_deflate(&zstream, Z_FINISH); - if (result != Z_STREAM_END) - die("deflate error (%d)", result); + + do { + result = git_deflate(&zstream, Z_FINISH); + if (result != Z_OK && result != Z_STREAM_END) + die("deflate error (%d)", result); + + out_len = zstream.next_out - compressed; + if (out_len > 0) { + write_or_die(1, compressed, out_len); + compressed_size += out_len; + zstream.next_out = compressed; + zstream.avail_out = sizeof(compressed); + } + } while (result != Z_STREAM_END); git_deflate_end(&zstream); - out_len = zstream.next_out - compressed; - write_or_die(1, compressed, out_len); - compressed_size += out_len; zip_offset += compressed_size; write_zip_data_desc(size, compressed_size, crc); |
