List Archive


Thread Index


From: Sergei Hrushev <>
Subject: Strange problem with zip_fopen_index/inflateInit2
Date: Thu, 19 May 2016 09:46:15 +0600


I just compiled libzip in Visual Studio 2015 and now trying to check if all is OK.
But this call seems to be always returning NULL for entries compressed via DEFLATE (I checking entry 0 only):

zf = zip_fopen_index(entry, 0, 0);

By tracing sources in debugger I found that the next line in zip_source_deflate.c returns -2:

 if ((ret=inflateInit2(&ctx->zstr, -MAX_WBITS)) != Z_OK) {


I checked on and it's written that Z_STREAM_ERROR is returned "if a parameters are invalid"

For example for entry 0 (named "compressable") of archive (from libzip/regress)
the value of ctx->zstr passed to inflateInit2 is as follows:

ctx->zstr    {next_in=0x00000000003f34d0 "KLD\x6" avail_in=5 total_in=3452816845 ...}    z_stream_s
        next_in        0x00000000003f34d0 "KLD\x6"    unsigned char *
        avail_in    5    unsigned int
        total_in    3452816845    unsigned long
        next_out    0xcdcdcdcdcdcdcdcd <Error reading characters of string.>    unsigned char *
        avail_out    3452816845    unsigned int
        total_out    3452816845    unsigned long
        msg            0x0000000000000000 <NULL>    char *
        state        0xcdcdcdcdcdcdcdcd {dummy=??? }    internal_state *
        zalloc        0x0000000000000000    void *(*)(void *, unsigned int, unsigned int)
        zfree        0x0000000000000000    void(*)(void *, void *)
        opaque        0x0000000000000000    void *
        data_type    -842150451    int
        adler        3452816845    unsigned long
        reserved    3452816845    unsigned long

zlib website says "The fields next_in, avail_in, zalloc, zfree and opaque must be initialized before by the caller."
It seems all these fields are initialized.

What else can be wrong in this structure?

P.S. I'm pretty sure zlib (1.2.8) itself works properly because libpng uses same lib file and works as expected.

Thank you very much in advance for any help!

Made by MHonArc.