Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JZLib 1.1.3 is not compatible with native Java ZLib implementation #17

Open
747mmHg opened this issue Oct 23, 2014 · 1 comment
Open

Comments

@747mmHg
Copy link

747mmHg commented Oct 23, 2014

Hello,

We encountered an error when trying to migrate our app from old version of jzlib (1.0.2) to latest one (1.1.3): latest version of jzlib is unable to parse some inputs which are perfectly parsed by both old version of jzlib and native Java implementation of zlib.
Here is the sample of such input:

    private static final byte[] INVALID = {120, -38, 98, 102, -30, 112, 76, 78, -50, 47, -51, 43, 41, 102, 100, 96, 96, -80, -25, -11, 77, 45, 46, 78, 76, 79, 117, 78, -51, 43, 73, 45, 98, 100, -80, -29, -25, 101, -51, -55, 79, -49, -52, 99, 100, 20, 41, 73, 73, -116, -49, -51, 79, -118, 79, -52, 75, 41, -54, -49, 76, -47, 51, 51, -41, -77, -112, 116, -124, 112, 20, -126, 93, -68, 21, -110, 74, 51, 115, 74, 20, -46, -14, -117, 20, 42, 44, -52, 88, 77, -12, 76, -12, -116, -22, -21, -103, 67, -4, -125, -21, 89, 83, -117, -77, -13, -117, 88, 10, -127, 96, 127, 123, 125, 61, 64};

    public void testJzlib() throws IOException {
        final byte[] source = INVALID;
        ByteArrayInputStream input = new ByteArrayInputStream(source);
        InputStream stream = new com.jcraft.jzlib.ZInputStream(input);
        byte[] bytes = new byte[512];
        int read = stream.read(bytes);
        System.out.println("Read: " + read);
        System.out.println("Bytes: " + Arrays.toString(bytes));
    }

    public void testNative() throws IOException {
        final byte[] source = INVALID;
        ByteArrayInputStream input = new ByteArrayInputStream(source);
        InputStream stream = new java.util.zip.InflaterInputStream(input);
        byte[] bytes = new byte[512];
        int read = stream.read(bytes);
        System.out.println("Read: " + read);
        System.out.println("Bytes: " + Arrays.toString(bytes));
    }

After running this code on jzlib 1.0.2 we got 118 bytes read (the same result as for native Java). But if we switch to jzlib 1.1.3 ZInputStream throws EOFException (while correctly read the data):

java.io.EOFException: Unexpected end of ZLIB input stream
    at com.jcraft.jzlib.InflaterInputStream.fill(InflaterInputStream.java:186)
    at com.jcraft.jzlib.InflaterInputStream.read(InflaterInputStream.java:106)
    at com.jcraft.jzlib.ZInputStream.read(ZInputStream.java:92)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)
@twonky4
Copy link

twonky4 commented Apr 1, 2019

Its' working with 1.0.7 but fails with version 1.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants