google / archive-patcher

Automatically exported from code.google.com/p/archive-patcher
Apache License 2.0
534 stars 74 forks source link

Some zlib versions fail the DefaultDeflateCompatibilityWindow compatability test #179

Open Adam- opened 3 years ago

Adam- commented 3 years ago

The new DefaultDeflateCompatibilityWindow().isCompatible() test fails on many Linux distros currently, including: Debian 10, 11, Fedora 32, and Arch, however passes on at least Ubuntu 18.0.4 and 20.04. Tested on OpenJDK 11. This is due to a change in zlib:

commit 43bfaba3d718a27c1b137b1d1aa90d9427ab4a4f
Author: Mark Adler <madler@alumni.caltech.edu>
Date:   Sun Aug 2 00:02:07 2015 -0700

    Align deflateParams() and its documentation in zlib.h.

    This updates the documentation to reflect the behavior of
    deflateParams() when it is not able to compress all of the input
    data provided so far due to insufficient output space.  It also
    assures that data provided is compressed before the parameter
    changes, even if at the beginning of the stream.

 deflate.c |  3 +--
 zlib.h    | 38 ++++++++++++++++++++++++++------------
 2 files changed, 27 insertions(+), 14 deletions(-)

which is present in zlib v1.2.9, v1.2.10, and v1.2.11.

The original behavior was restored upstream in the develop branch in

commit f9694097dd69354b03cb8af959094c7f260db0a1
Author: Mark Adler <madler@alumni.caltech.edu>
Date:   Mon Jan 16 09:49:35 2017 -0800

    Permit a deflateParams() parameter change as soon as possible.

    This commit allows a parameter change even if the input data has
    not all been compressed and copied to the application output
    buffer, so long as all of the input data has been compressed to
    the internal pending output buffer. This also allows an immediate
    deflateParams change so long as there have been no deflate calls
    since initialization or reset.

which is unreleased - however Ubuntu is manually patching zlib with it in at least 18.04 and 20.04 - which is why those work.

We have additionally discovered disabling caching on the deflate compressor in DefaultDeflateCompatibilityWindow fixes this, too, eg:

    DeflateCompressor compressor = new DeflateCompressor();
    compressor.setCaching(false);

however I don't know if this is a safe change to make.

Adam- commented 2 years ago

We have a commit which works around this issue by avoiding caching compressors if this zlib bug is present, if anyone else is experiencing the same problem: https://github.com/runelite/archive-patcher/commit/d394be050be75f4b14e2bc16b3e48f9cd6a39bfc

hamid97m commented 1 year ago

It's fixed in my PR