11.1Schristos
21.1Schristos                Frequently Asked Questions about zlib
31.1Schristos
41.1Schristos
51.1SchristosIf your question is not there, please check the zlib home page
61.1.1.2Schristoshttp://zlib.net/ which may have more recent information.
71.1.1.3SchristosThe latest zlib FAQ is at http://zlib.net/zlib_faq.html
81.1Schristos
91.1Schristos
101.1Schristos 1. Is zlib Y2K-compliant?
111.1Schristos
121.1Schristos    Yes. zlib doesn't handle dates.
131.1Schristos
141.1Schristos 2. Where can I get a Windows DLL version?
151.1Schristos
161.1.1.2Schristos    The zlib sources can be compiled without change to produce a DLL.  See the
171.1.1.3Schristos    file win32/DLL_FAQ.txt in the zlib distribution.
181.1Schristos
191.1Schristos 3. Where can I get a Visual Basic interface to zlib?
201.1Schristos
211.1Schristos    See
221.1.1.2Schristos        * http://marknelson.us/1997/01/01/zlib-engine/
231.1Schristos        * win32/DLL_FAQ.txt in the zlib distribution
241.1Schristos
251.1Schristos 4. compress() returns Z_BUF_ERROR.
261.1Schristos
271.1.1.2Schristos    Make sure that before the call of compress(), the length of the compressed
281.1.1.2Schristos    buffer is equal to the available size of the compressed buffer and not
291.1.1.2Schristos    zero.  For Visual Basic, check that this parameter is passed by reference
301.1Schristos    ("as any"), not by value ("as long").
311.1Schristos
321.1Schristos 5. deflate() or inflate() returns Z_BUF_ERROR.
331.1Schristos
341.1.1.2Schristos    Before making the call, make sure that avail_in and avail_out are not zero.
351.1.1.2Schristos    When setting the parameter flush equal to Z_FINISH, also make sure that
361.1.1.2Schristos    avail_out is big enough to allow processing all pending input.  Note that a
371.1.1.2Schristos    Z_BUF_ERROR is not fatal--another call to deflate() or inflate() can be
381.1.1.2Schristos    made with more input or output space.  A Z_BUF_ERROR may in fact be
391.1.1.2Schristos    unavoidable depending on how the functions are used, since it is not
401.1.1.2Schristos    possible to tell whether or not there is more output pending when
411.1.1.2Schristos    strm.avail_out returns with zero.  See http://zlib.net/zlib_how.html for a
421.1.1.2Schristos    heavily annotated example.
431.1Schristos
441.1Schristos 6. Where's the zlib documentation (man pages, etc.)?
451.1Schristos
461.1.1.2Schristos    It's in zlib.h .  Examples of zlib usage are in the files test/example.c
471.1.1.2Schristos    and test/minigzip.c, with more in examples/ .
481.1Schristos
491.1Schristos 7. Why don't you use GNU autoconf or libtool or ...?
501.1Schristos
511.1.1.2Schristos    Because we would like to keep zlib as a very small and simple package.
521.1.1.2Schristos    zlib is rather portable and doesn't need much configuration.
531.1Schristos
541.1Schristos 8. I found a bug in zlib.
551.1Schristos
561.1.1.2Schristos    Most of the time, such problems are due to an incorrect usage of zlib.
571.1.1.2Schristos    Please try to reproduce the problem with a small program and send the
581.1.1.2Schristos    corresponding source to us at zlib@gzip.org .  Do not send multi-megabyte
591.1.1.2Schristos    data files without prior agreement.
601.1Schristos
611.1Schristos 9. Why do I get "undefined reference to gzputc"?
621.1Schristos
631.1Schristos    If "make test" produces something like
641.1Schristos
651.1Schristos       example.o(.text+0x154): undefined reference to `gzputc'
661.1Schristos
671.1Schristos    check that you don't have old files libz.* in /usr/lib, /usr/local/lib or
681.1Schristos    /usr/X11R6/lib. Remove any old versions, then do "make install".
691.1Schristos
701.1Schristos10. I need a Delphi interface to zlib.
711.1Schristos
721.1Schristos    See the contrib/delphi directory in the zlib distribution.
731.1Schristos
741.1Schristos11. Can zlib handle .zip archives?
751.1Schristos
761.1Schristos    Not by itself, no.  See the directory contrib/minizip in the zlib
771.1Schristos    distribution.
781.1Schristos
791.1Schristos12. Can zlib handle .Z files?
801.1Schristos
811.1.1.2Schristos    No, sorry.  You have to spawn an uncompress or gunzip subprocess, or adapt
821.1Schristos    the code of uncompress on your own.
831.1Schristos
841.1Schristos13. How can I make a Unix shared library?
851.1Schristos
861.1.1.2Schristos    By default a shared (and a static) library is built for Unix.  So:
871.1.1.2Schristos
881.1.1.2Schristos    make distclean
891.1.1.2Schristos    ./configure
901.1Schristos    make
911.1Schristos
921.1Schristos14. How do I install a shared zlib library on Unix?
931.1Schristos
941.1Schristos    After the above, then:
951.1Schristos
961.1Schristos    make install
971.1Schristos
981.1Schristos    However, many flavors of Unix come with a shared zlib already installed.
991.1Schristos    Before going to the trouble of compiling a shared version of zlib and
1001.1.1.2Schristos    trying to install it, you may want to check if it's already there!  If you
1011.1.1.2Schristos    can #include <zlib.h>, it's there.  The -lz option will probably link to
1021.1.1.2Schristos    it.  You can check the version at the top of zlib.h or with the
1031.1.1.2Schristos    ZLIB_VERSION symbol defined in zlib.h .
1041.1Schristos
1051.1Schristos15. I have a question about OttoPDF.
1061.1Schristos
1071.1Schristos    We are not the authors of OttoPDF. The real author is on the OttoPDF web
1081.1Schristos    site: Joel Hainley, jhainley@myndkryme.com.
1091.1Schristos
1101.1Schristos16. Can zlib decode Flate data in an Adobe PDF file?
1111.1Schristos
1121.1.1.2Schristos    Yes. See http://www.pdflib.com/ . To modify PDF forms, see
1131.1.1.2Schristos    http://sourceforge.net/projects/acroformtool/ .
1141.1Schristos
1151.1Schristos17. Why am I getting this "register_frame_info not found" error on Solaris?
1161.1Schristos
1171.1Schristos    After installing zlib 1.1.4 on Solaris 2.6, running applications using zlib
1181.1Schristos    generates an error such as:
1191.1Schristos
1201.1Schristos        ld.so.1: rpm: fatal: relocation error: file /usr/local/lib/libz.so:
1211.1Schristos        symbol __register_frame_info: referenced symbol not found
1221.1Schristos
1231.1Schristos    The symbol __register_frame_info is not part of zlib, it is generated by
1241.1.1.2Schristos    the C compiler (cc or gcc).  You must recompile applications using zlib
1251.1.1.2Schristos    which have this problem.  This problem is specific to Solaris.  See
1261.1Schristos    http://www.sunfreeware.com for Solaris versions of zlib and applications
1271.1Schristos    using zlib.
1281.1Schristos
1291.1Schristos18. Why does gzip give an error on a file I make with compress/deflate?
1301.1Schristos
1311.1Schristos    The compress and deflate functions produce data in the zlib format, which
1321.1.1.2Schristos    is different and incompatible with the gzip format.  The gz* functions in
1331.1.1.2Schristos    zlib on the other hand use the gzip format.  Both the zlib and gzip formats
1341.1.1.2Schristos    use the same compressed data format internally, but have different headers
1351.1.1.2Schristos    and trailers around the compressed data.
1361.1Schristos
1371.1Schristos19. Ok, so why are there two different formats?
1381.1Schristos
1391.1.1.2Schristos    The gzip format was designed to retain the directory information about a
1401.1.1.2Schristos    single file, such as the name and last modification date.  The zlib format
1411.1.1.2Schristos    on the other hand was designed for in-memory and communication channel
1421.1.1.2Schristos    applications, and has a much more compact header and trailer and uses a
1431.1.1.2Schristos    faster integrity check than gzip.
1441.1Schristos
1451.1Schristos20. Well that's nice, but how do I make a gzip file in memory?
1461.1Schristos
1471.1Schristos    You can request that deflate write the gzip format instead of the zlib
1481.1.1.2Schristos    format using deflateInit2().  You can also request that inflate decode the
1491.1.1.2Schristos    gzip format using inflateInit2().  Read zlib.h for more details.
1501.1Schristos
1511.1Schristos21. Is zlib thread-safe?
1521.1Schristos
1531.1.1.2Schristos    Yes.  However any library routines that zlib uses and any application-
1541.1.1.2Schristos    provided memory allocation routines must also be thread-safe.  zlib's gz*
1551.1Schristos    functions use stdio library routines, and most of zlib's functions use the
1561.1.1.2Schristos    library memory allocation routines by default.  zlib's *Init* functions
1571.1.1.2Schristos    allow for the application to provide custom memory allocation routines.
1581.1Schristos
1591.1Schristos    Of course, you should only operate on any given zlib or gzip stream from a
1601.1Schristos    single thread at a time.
1611.1Schristos
1621.1Schristos22. Can I use zlib in my commercial application?
1631.1Schristos
1641.1.1.2Schristos    Yes.  Please read the license in zlib.h.
1651.1Schristos
1661.1Schristos23. Is zlib under the GNU license?
1671.1Schristos
1681.1.1.2Schristos    No.  Please read the license in zlib.h.
1691.1Schristos
1701.1Schristos24. The license says that altered source versions must be "plainly marked". So
1711.1Schristos    what exactly do I need to do to meet that requirement?
1721.1Schristos
1731.1.1.2Schristos    You need to change the ZLIB_VERSION and ZLIB_VERNUM #defines in zlib.h.  In
1741.1Schristos    particular, the final version number needs to be changed to "f", and an
1751.1.1.2Schristos    identification string should be appended to ZLIB_VERSION.  Version numbers
1761.1Schristos    x.x.x.f are reserved for modifications to zlib by others than the zlib
1771.1.1.2Schristos    maintainers.  For example, if the version of the base zlib you are altering
1781.1Schristos    is "1.2.3.4", then in zlib.h you should change ZLIB_VERNUM to 0x123f, and
1791.1.1.2Schristos    ZLIB_VERSION to something like "1.2.3.f-zachary-mods-v3".  You can also
1801.1Schristos    update the version strings in deflate.c and inftrees.c.
1811.1Schristos
1821.1Schristos    For altered source distributions, you should also note the origin and
1831.1Schristos    nature of the changes in zlib.h, as well as in ChangeLog and README, along
1841.1.1.2Schristos    with the dates of the alterations.  The origin should include at least your
1851.1Schristos    name (or your company's name), and an email address to contact for help or
1861.1Schristos    issues with the library.
1871.1Schristos
1881.1Schristos    Note that distributing a compiled zlib library along with zlib.h and
1891.1Schristos    zconf.h is also a source distribution, and so you should change
1901.1Schristos    ZLIB_VERSION and ZLIB_VERNUM and note the origin and nature of the changes
1911.1Schristos    in zlib.h as you would for a full source distribution.
1921.1Schristos
1931.1Schristos25. Will zlib work on a big-endian or little-endian architecture, and can I
1941.1Schristos    exchange compressed data between them?
1951.1Schristos
1961.1Schristos    Yes and yes.
1971.1Schristos
1981.1Schristos26. Will zlib work on a 64-bit machine?
1991.1Schristos
2001.1.1.2Schristos    Yes.  It has been tested on 64-bit machines, and has no dependence on any
2011.1.1.2Schristos    data types being limited to 32-bits in length.  If you have any
2021.1Schristos    difficulties, please provide a complete problem report to zlib@gzip.org
2031.1Schristos
2041.1Schristos27. Will zlib decompress data from the PKWare Data Compression Library?
2051.1Schristos
2061.1.1.2Schristos    No.  The PKWare DCL uses a completely different compressed data format than
2071.1.1.2Schristos    does PKZIP and zlib.  However, you can look in zlib's contrib/blast
2081.1Schristos    directory for a possible solution to your problem.
2091.1Schristos
2101.1Schristos28. Can I access data randomly in a compressed stream?
2111.1Schristos
2121.1.1.2Schristos    No, not without some preparation.  If when compressing you periodically use
2131.1.1.2Schristos    Z_FULL_FLUSH, carefully write all the pending data at those points, and
2141.1.1.2Schristos    keep an index of those locations, then you can start decompression at those
2151.1.1.2Schristos    points.  You have to be careful to not use Z_FULL_FLUSH too often, since it
2161.1.1.2Schristos    can significantly degrade compression.  Alternatively, you can scan a
2171.1.1.2Schristos    deflate stream once to generate an index, and then use that index for
2181.1.1.2Schristos    random access.  See examples/zran.c .
2191.1Schristos
2201.1Schristos29. Does zlib work on MVS, OS/390, CICS, etc.?
2211.1Schristos
2221.1.1.2Schristos    It has in the past, but we have not heard of any recent evidence.  There
2231.1.1.2Schristos    were working ports of zlib 1.1.4 to MVS, but those links no longer work.
2241.1.1.2Schristos    If you know of recent, successful applications of zlib on these operating
2251.1.1.2Schristos    systems, please let us know.  Thanks.
2261.1Schristos
2271.1.1.2Schristos30. Is there some simpler, easier to read version of inflate I can look at to
2281.1.1.2Schristos    understand the deflate format?
2291.1Schristos
2301.1.1.2Schristos    First off, you should read RFC 1951.  Second, yes.  Look in zlib's
2311.1Schristos    contrib/puff directory.
2321.1Schristos
2331.1Schristos31. Does zlib infringe on any patents?
2341.1Schristos
2351.1.1.2Schristos    As far as we know, no.  In fact, that was originally the whole point behind
2361.1.1.2Schristos    zlib.  Look here for some more information:
2371.1Schristos
2381.1Schristos    http://www.gzip.org/#faq11
2391.1Schristos
2401.1Schristos32. Can zlib work with greater than 4 GB of data?
2411.1Schristos
2421.1.1.2Schristos    Yes.  inflate() and deflate() will process any amount of data correctly.
2431.1Schristos    Each call of inflate() or deflate() is limited to input and output chunks
2441.1Schristos    of the maximum value that can be stored in the compiler's "unsigned int"
2451.1.1.2Schristos    type, but there is no limit to the number of chunks.  Note however that the
2461.1.1.2Schristos    strm.total_in and strm_total_out counters may be limited to 4 GB.  These
2471.1Schristos    counters are provided as a convenience and are not used internally by
2481.1.1.2Schristos    inflate() or deflate().  The application can easily set up its own counters
2491.1Schristos    updated after each call of inflate() or deflate() to count beyond 4 GB.
2501.1Schristos    compress() and uncompress() may be limited to 4 GB, since they operate in a
2511.1.1.2Schristos    single call.  gzseek() and gztell() may be limited to 4 GB depending on how
2521.1.1.2Schristos    zlib is compiled.  See the zlibCompileFlags() function in zlib.h.
2531.1Schristos
2541.1.1.2Schristos    The word "may" appears several times above since there is a 4 GB limit only
2551.1.1.2Schristos    if the compiler's "long" type is 32 bits.  If the compiler's "long" type is
2561.1.1.2Schristos    64 bits, then the limit is 16 exabytes.
2571.1Schristos
2581.1Schristos33. Does zlib have any security vulnerabilities?
2591.1Schristos
2601.1.1.2Schristos    The only one that we are aware of is potentially in gzprintf().  If zlib is
2611.1.1.2Schristos    compiled to use sprintf() or vsprintf(), then there is no protection
2621.1.1.2Schristos    against a buffer overflow of an 8K string space (or other value as set by
2631.1.1.2Schristos    gzbuffer()), other than the caller of gzprintf() assuring that the output
2641.1.1.2Schristos    will not exceed 8K.  On the other hand, if zlib is compiled to use
2651.1.1.2Schristos    snprintf() or vsnprintf(), which should normally be the case, then there is
2661.1.1.2Schristos    no vulnerability.  The ./configure script will display warnings if an
2671.1.1.2Schristos    insecure variation of sprintf() will be used by gzprintf().  Also the
2681.1.1.2Schristos    zlibCompileFlags() function will return information on what variant of
2691.1.1.2Schristos    sprintf() is used by gzprintf().
2701.1Schristos
2711.1Schristos    If you don't have snprintf() or vsnprintf() and would like one, you can
2721.1Schristos    find a portable implementation here:
2731.1Schristos
2741.1Schristos        http://www.ijs.si/software/snprintf/
2751.1Schristos
2761.1.1.2Schristos    Note that you should be using the most recent version of zlib.  Versions
2771.1.1.2Schristos    1.1.3 and before were subject to a double-free vulnerability, and versions
2781.1.1.2Schristos    1.2.1 and 1.2.2 were subject to an access exception when decompressing
2791.1.1.2Schristos    invalid compressed data.
2801.1Schristos
2811.1Schristos34. Is there a Java version of zlib?
2821.1Schristos
2831.1Schristos    Probably what you want is to use zlib in Java. zlib is already included
2841.1Schristos    as part of the Java SDK in the java.util.zip package. If you really want
2851.1Schristos    a version of zlib written in the Java language, look on the zlib home
2861.1.1.2Schristos    page for links: http://zlib.net/ .
2871.1Schristos
2881.1Schristos35. I get this or that compiler or source-code scanner warning when I crank it
2891.1Schristos    up to maximally-pedantic. Can't you guys write proper code?
2901.1Schristos
2911.1Schristos    Many years ago, we gave up attempting to avoid warnings on every compiler
2921.1.1.2Schristos    in the universe.  It just got to be a waste of time, and some compilers
2931.1.1.2Schristos    were downright silly as well as contradicted each other.  So now, we simply
2941.1.1.2Schristos    make sure that the code always works.
2951.1Schristos
2961.1Schristos36. Valgrind (or some similar memory access checker) says that deflate is
2971.1Schristos    performing a conditional jump that depends on an uninitialized value.
2981.1Schristos    Isn't that a bug?
2991.1Schristos
3001.1.1.2Schristos    No.  That is intentional for performance reasons, and the output of deflate
3011.1.1.2Schristos    is not affected.  This only started showing up recently since zlib 1.2.x
3021.1.1.2Schristos    uses malloc() by default for allocations, whereas earlier versions used
3031.1.1.2Schristos    calloc(), which zeros out the allocated memory.  Even though the code was
3041.1.1.2Schristos    correct, versions 1.2.4 and later was changed to not stimulate these
3051.1.1.2Schristos    checkers.
3061.1Schristos
3071.1Schristos37. Will zlib read the (insert any ancient or arcane format here) compressed
3081.1Schristos    data format?
3091.1Schristos
3101.1Schristos    Probably not. Look in the comp.compression FAQ for pointers to various
3111.1Schristos    formats and associated software.
3121.1Schristos
3131.1Schristos38. How can I encrypt/decrypt zip files with zlib?
3141.1Schristos
3151.1.1.2Schristos    zlib doesn't support encryption.  The original PKZIP encryption is very
3161.1.1.2Schristos    weak and can be broken with freely available programs.  To get strong
3171.1.1.2Schristos    encryption, use GnuPG, http://www.gnupg.org/ , which already includes zlib
3181.1.1.2Schristos    compression.  For PKZIP compatible "encryption", look at
3191.1.1.2Schristos    http://www.info-zip.org/
3201.1Schristos
3211.1Schristos39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
3221.1Schristos
3231.1.1.2Schristos    "gzip" is the gzip format, and "deflate" is the zlib format.  They should
3241.1.1.2Schristos    probably have called the second one "zlib" instead to avoid confusion with
3251.1.1.2Schristos    the raw deflate compressed data format.  While the HTTP 1.1 RFC 2616
3261.1Schristos    correctly points to the zlib specification in RFC 1950 for the "deflate"
3271.1Schristos    transfer encoding, there have been reports of servers and browsers that
3281.1Schristos    incorrectly produce or expect raw deflate data per the deflate
3291.1.1.2Schristos    specification in RFC 1951, most notably Microsoft.  So even though the
3301.1Schristos    "deflate" transfer encoding using the zlib format would be the more
3311.1Schristos    efficient approach (and in fact exactly what the zlib format was designed
3321.1Schristos    for), using the "gzip" transfer encoding is probably more reliable due to
3331.1Schristos    an unfortunate choice of name on the part of the HTTP 1.1 authors.
3341.1Schristos
3351.1Schristos    Bottom line: use the gzip format for HTTP 1.1 encoding.
3361.1Schristos
3371.1Schristos40. Does zlib support the new "Deflate64" format introduced by PKWare?
3381.1Schristos
3391.1.1.2Schristos    No.  PKWare has apparently decided to keep that format proprietary, since
3401.1.1.2Schristos    they have not documented it as they have previous compression formats.  In
3411.1.1.2Schristos    any case, the compression improvements are so modest compared to other more
3421.1.1.2Schristos    modern approaches, that it's not worth the effort to implement.
3431.1.1.2Schristos
3441.1.1.2Schristos41. I'm having a problem with the zip functions in zlib, can you help?
3451.1.1.2Schristos
3461.1.1.2Schristos    There are no zip functions in zlib.  You are probably using minizip by
3471.1.1.2Schristos    Giles Vollant, which is found in the contrib directory of zlib.  It is not
3481.1.1.2Schristos    part of zlib.  In fact none of the stuff in contrib is part of zlib.  The
3491.1.1.2Schristos    files in there are not supported by the zlib authors.  You need to contact
3501.1.1.2Schristos    the authors of the respective contribution for help.
3511.1.1.2Schristos
3521.1.1.2Schristos42. The match.asm code in contrib is under the GNU General Public License.
3531.1.1.2Schristos    Since it's part of zlib, doesn't that mean that all of zlib falls under the
3541.1.1.2Schristos    GNU GPL?
3551.1.1.2Schristos
3561.1.1.2Schristos    No.  The files in contrib are not part of zlib.  They were contributed by
3571.1.1.2Schristos    other authors and are provided as a convenience to the user within the zlib
3581.1.1.2Schristos    distribution.  Each item in contrib has its own license.
3591.1.1.2Schristos
3601.1.1.2Schristos43. Is zlib subject to export controls?  What is its ECCN?
3611.1.1.2Schristos
3621.1.1.2Schristos    zlib is not subject to export controls, and so is classified as EAR99.
3631.1Schristos
3641.1.1.2Schristos44. Can you please sign these lengthy legal documents and fax them back to us
3651.1Schristos    so that we can use your software in our product?
3661.1Schristos
3671.1Schristos    No. Go away. Shoo.
368