Skip to content

Commit 1a5c1cc

Browse files
committed
Merge branch 'jt/archive-zip-deflate-fix' into next
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
2 parents 125493b + 5673005 commit 1a5c1cc

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

archive-zip.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,22 @@ static int write_zip_entry(struct archiver_args *args,
492492

493493
zstream.next_in = buf;
494494
zstream.avail_in = 0;
495-
result = git_deflate(&zstream, Z_FINISH);
496-
if (result != Z_STREAM_END)
497-
die("deflate error (%d)", result);
495+
496+
do {
497+
result = git_deflate(&zstream, Z_FINISH);
498+
if (result != Z_OK && result != Z_STREAM_END)
499+
die("deflate error (%d)", result);
500+
501+
out_len = zstream.next_out - compressed;
502+
if (out_len > 0) {
503+
write_or_die(1, compressed, out_len);
504+
compressed_size += out_len;
505+
zstream.next_out = compressed;
506+
zstream.avail_out = sizeof(compressed);
507+
}
508+
} while (result != Z_STREAM_END);
498509

499510
git_deflate_end(&zstream);
500-
out_len = zstream.next_out - compressed;
501-
write_or_die(1, compressed, out_len);
502-
compressed_size += out_len;
503511
zip_offset += compressed_size;
504512

505513
write_zip_data_desc(size, compressed_size, crc);

0 commit comments

Comments
 (0)