aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party
diff options
context:
space:
mode:
authorGravatar Damien Martin-Guillerez <dmarting@google.com>2015-09-11 15:17:26 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-09-11 15:26:16 +0000
commit676f39ae51536d2697627ddc352f4af4782fc893 (patch)
treebb637c912f59239610fa2907e6810332a74ecd42 /third_party
parent4009d2c4938a768158d7ae2ea848933a96737d25 (diff)
Fix ijar compression
Ijar was compressing with the zlib wrapper, which is incompatible with the ZIP format. Unfortunately, the zlib wrapper is totally undocumented. Fixes #436. -- MOS_MIGRATED_REVID=102846162
Diffstat (limited to 'third_party')
-rwxr-xr-xthird_party/ijar/test/zip_test.sh23
-rw-r--r--third_party/ijar/zip.cc4
2 files changed, 26 insertions, 1 deletions
diff --git a/third_party/ijar/test/zip_test.sh b/third_party/ijar/test/zip_test.sh
index 4b92f32c43..19fd3de72e 100755
--- a/third_party/ijar/test/zip_test.sh
+++ b/third_party/ijar/test/zip_test.sh
@@ -85,4 +85,27 @@ function test_zipper() {
expect_not_log "path"
}
+function test_zipper_compression() {
+ echo -n > ${TEST_TMPDIR}/a
+ for i in $(seq 1 1000); do
+ echo -n "a" >> ${TEST_TMPDIR}/a
+ done
+ $ZIPPER cCf ${TEST_TMPDIR}/output.zip ${TEST_TMPDIR}/a
+ local out_size=$(cat ${TEST_TMPDIR}/output.zip | wc -c | xargs)
+ local in_size=$(cat ${TEST_TMPDIR}/a | wc -c | xargs)
+ check_gt "${in_size}" "${out_size}" "Output size is greater than input size"
+
+ rm -fr ${TEST_TMPDIR}/out
+ mkdir -p ${TEST_TMPDIR}/out
+ (cd ${TEST_TMPDIR}/out && $ZIPPER x ${TEST_TMPDIR}/output.zip)
+ diff ${TEST_TMPDIR}/a ${TEST_TMPDIR}/out/a &> $TEST_log \
+ || fail "Unzip using zipper after zipper output differ"
+
+ rm -fr ${TEST_TMPDIR}/out
+ mkdir -p ${TEST_TMPDIR}/out
+ (cd ${TEST_TMPDIR}/out && $UNZIP -q ${TEST_TMPDIR}/output.zip)
+ diff ${TEST_TMPDIR}/a ${TEST_TMPDIR}/out/a &> $TEST_log \
+ || fail "Unzip after zipper output differ"
+}
+
run_suite "zipper tests"
diff --git a/third_party/ijar/zip.cc b/third_party/ijar/zip.cc
index 51e308de7d..5a3d1a589c 100644
--- a/third_party/ijar/zip.cc
+++ b/third_party/ijar/zip.cc
@@ -887,7 +887,9 @@ size_t TryDeflate(u1 *buf, size_t length) {
stream.next_in = buf;
stream.next_out = outbuf;
- if (deflateInit(&stream, Z_DEFAULT_COMPRESSION) != Z_OK) {
+ // deflateInit2 negative windows size prevent the zlib wrapper to be used.
+ if (deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
+ -MAX_WBITS, 8, Z_DEFAULT_STRATEGY) != Z_OK) {
// Failure to compress => return the buffer uncompressed
free(outbuf);
return length;