Git fork

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

+14 -6
+14 -6
archive-zip.c
··· 492 492 493 493 zstream.next_in = buf; 494 494 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); 498 509 499 510 git_deflate_end(&zstream); 500 - out_len = zstream.next_out - compressed; 501 - write_or_die(1, compressed, out_len); 502 - compressed_size += out_len; 503 511 zip_offset += compressed_size; 504 512 505 513 write_zip_data_desc(size, compressed_size, crc);