FAQ revision 1.1
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.1Schristoshttp://www.zlib.org which may have more recent information.
71.1SchristosThe lastest zlib FAQ is at http://www.gzip.org/zlib/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.1Schristos    The zlib sources can be compiled without change to produce a DLL.
171.1Schristos    See the file win32/DLL_FAQ.txt in the zlib distribution.
181.1Schristos    Pointers to the precompiled DLL are found in the zlib web site at
191.1Schristos    http://www.zlib.org.
201.1Schristos
211.1Schristos 3. Where can I get a Visual Basic interface to zlib?
221.1Schristos
231.1Schristos    See
241.1Schristos        * http://www.dogma.net/markn/articles/zlibtool/zlibtool.htm
251.1Schristos        * contrib/visual-basic.txt in the zlib distribution
261.1Schristos        * win32/DLL_FAQ.txt in the zlib distribution
271.1Schristos
281.1Schristos 4. compress() returns Z_BUF_ERROR.
291.1Schristos
301.1Schristos    Make sure that before the call of compress, the length of the compressed
311.1Schristos    buffer is equal to the total size of the compressed buffer and not
321.1Schristos    zero. For Visual Basic, check that this parameter is passed by reference
331.1Schristos    ("as any"), not by value ("as long").
341.1Schristos
351.1Schristos 5. deflate() or inflate() returns Z_BUF_ERROR.
361.1Schristos
371.1Schristos    Before making the call, make sure that avail_in and avail_out are not
381.1Schristos    zero. When setting the parameter flush equal to Z_FINISH, also make sure
391.1Schristos    that avail_out is big enough to allow processing all pending input.
401.1Schristos    Note that a Z_BUF_ERROR is not fatal--another call to deflate() or
411.1Schristos    inflate() can be made with more input or output space. A Z_BUF_ERROR
421.1Schristos    may in fact be unavoidable depending on how the functions are used, since
431.1Schristos    it is not possible to tell whether or not there is more output pending
441.1Schristos    when strm.avail_out returns with zero.
451.1Schristos
461.1Schristos 6. Where's the zlib documentation (man pages, etc.)?
471.1Schristos
481.1Schristos    It's in zlib.h for the moment, and Francis S. Lin has converted it to a
491.1Schristos    web page zlib.html. Volunteers to transform this to Unix-style man pages,
501.1Schristos    please contact us (zlib@gzip.org). Examples of zlib usage are in the files
511.1Schristos    example.c and minigzip.c.
521.1Schristos
531.1Schristos 7. Why don't you use GNU autoconf or libtool or ...?
541.1Schristos
551.1Schristos    Because we would like to keep zlib as a very small and simple
561.1Schristos    package. zlib is rather portable and doesn't need much configuration.
571.1Schristos
581.1Schristos 8. I found a bug in zlib.
591.1Schristos
601.1Schristos    Most of the time, such problems are due to an incorrect usage of
611.1Schristos    zlib. Please try to reproduce the problem with a small program and send
621.1Schristos    the corresponding source to us at zlib@gzip.org . Do not send
631.1Schristos    multi-megabyte data files without prior agreement.
641.1Schristos
651.1Schristos 9. Why do I get "undefined reference to gzputc"?
661.1Schristos
671.1Schristos    If "make test" produces something like
681.1Schristos
691.1Schristos       example.o(.text+0x154): undefined reference to `gzputc'
701.1Schristos
711.1Schristos    check that you don't have old files libz.* in /usr/lib, /usr/local/lib or
721.1Schristos    /usr/X11R6/lib. Remove any old versions, then do "make install".
731.1Schristos
741.1Schristos10. I need a Delphi interface to zlib.
751.1Schristos
761.1Schristos    See the contrib/delphi directory in the zlib distribution.
771.1Schristos
781.1Schristos11. Can zlib handle .zip archives?
791.1Schristos
801.1Schristos    Not by itself, no.  See the directory contrib/minizip in the zlib
811.1Schristos    distribution.
821.1Schristos
831.1Schristos12. Can zlib handle .Z files?
841.1Schristos
851.1Schristos    No, sorry. You have to spawn an uncompress or gunzip subprocess, or adapt
861.1Schristos    the code of uncompress on your own.
871.1Schristos
881.1Schristos13. How can I make a Unix shared library?
891.1Schristos
901.1Schristos    make clean
911.1Schristos    ./configure -s
921.1Schristos    make
931.1Schristos
941.1Schristos14. How do I install a shared zlib library on Unix?
951.1Schristos
961.1Schristos    After the above, then:
971.1Schristos
981.1Schristos    make install
991.1Schristos
1001.1Schristos    However, many flavors of Unix come with a shared zlib already installed.
1011.1Schristos    Before going to the trouble of compiling a shared version of zlib and
1021.1Schristos    trying to install it, you may want to check if it's already there! If you
1031.1Schristos    can #include <zlib.h>, it's there. The -lz option will probably link to it.
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.1Schristos    Yes. See http://www.fastio.com/ (ClibPDF), or http://www.pdflib.com/ .
1131.1Schristos    To modify PDF forms, see 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.1Schristos    the C compiler (cc or gcc). You must recompile applications using zlib
1251.1Schristos    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.1Schristos    is different and incompatible with the gzip format. The gz* functions in
1331.1Schristos    zlib on the other hand use the gzip format. Both the zlib and gzip
1341.1Schristos    formats use the same compressed data format internally, but have different
1351.1Schristos    headers and trailers around the compressed data.
1361.1Schristos
1371.1Schristos19. Ok, so why are there two different formats?
1381.1Schristos
1391.1Schristos    The gzip format was designed to retain the directory information about
1401.1Schristos    a single file, such as the name and last modification date. The zlib
1411.1Schristos    format on the other hand was designed for in-memory and communication
1421.1Schristos    channel applications, and has a much more compact header and trailer and
1431.1Schristos    uses a 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.1Schristos    format using deflateInit2(). You can also request that inflate decode
1491.1Schristos    the gzip format using inflateInit2(). Read zlib.h for more details.
1501.1Schristos
1511.1Schristos21. Is zlib thread-safe?
1521.1Schristos
1531.1Schristos    Yes. However any library routines that zlib uses and any application-
1541.1Schristos    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.1Schristos    library memory allocation routines by default. zlib's Init functions allow
1571.1Schristos    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.1Schristos    Yes. Please read the license in zlib.h.
1651.1Schristos
1661.1Schristos23. Is zlib under the GNU license?
1671.1Schristos
1681.1Schristos    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.1Schristos    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.1Schristos    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.1Schristos    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.1Schristos    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.1Schristos    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.1Schristos    It should. It has been tested on 64-bit machines, and has no dependence
2011.1Schristos    on any 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.1Schristos    No. The PKWare DCL uses a completely different compressed data format
2071.1Schristos    than 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.1Schristos    No, not without some preparation. If when compressing you periodically
2131.1Schristos    use Z_FULL_FLUSH, carefully write all the pending data at those points,
2141.1Schristos    and keep an index of those locations, then you can start decompression
2151.1Schristos    at those points. You have to be careful to not use Z_FULL_FLUSH too
2161.1Schristos    often, since it can significantly degrade compression.
2171.1Schristos
2181.1Schristos29. Does zlib work on MVS, OS/390, CICS, etc.?
2191.1Schristos
2201.1Schristos    We don't know for sure. We have heard occasional reports of success on
2211.1Schristos    these systems. If you do use it on one of these, please provide us with
2221.1Schristos    a report, instructions, and patches that we can reference when we get
2231.1Schristos    these questions. Thanks.
2241.1Schristos
2251.1Schristos30. Is there some simpler, easier to read version of inflate I can look at
2261.1Schristos    to understand the deflate format?
2271.1Schristos
2281.1Schristos    First off, you should read RFC 1951. Second, yes. Look in zlib's
2291.1Schristos    contrib/puff directory.
2301.1Schristos
2311.1Schristos31. Does zlib infringe on any patents?
2321.1Schristos
2331.1Schristos    As far as we know, no. In fact, that was originally the whole point behind
2341.1Schristos    zlib. Look here for some more information:
2351.1Schristos
2361.1Schristos    http://www.gzip.org/#faq11
2371.1Schristos
2381.1Schristos32. Can zlib work with greater than 4 GB of data?
2391.1Schristos
2401.1Schristos    Yes. inflate() and deflate() will process any amount of data correctly.
2411.1Schristos    Each call of inflate() or deflate() is limited to input and output chunks
2421.1Schristos    of the maximum value that can be stored in the compiler's "unsigned int"
2431.1Schristos    type, but there is no limit to the number of chunks. Note however that the
2441.1Schristos    strm.total_in and strm_total_out counters may be limited to 4 GB. These
2451.1Schristos    counters are provided as a convenience and are not used internally by
2461.1Schristos    inflate() or deflate(). The application can easily set up its own counters
2471.1Schristos    updated after each call of inflate() or deflate() to count beyond 4 GB.
2481.1Schristos    compress() and uncompress() may be limited to 4 GB, since they operate in a
2491.1Schristos    single call. gzseek() and gztell() may be limited to 4 GB depending on how
2501.1Schristos    zlib is compiled. See the zlibCompileFlags() function in zlib.h.
2511.1Schristos
2521.1Schristos    The word "may" appears several times above since there is a 4 GB limit
2531.1Schristos    only if the compiler's "long" type is 32 bits. If the compiler's "long"
2541.1Schristos    type is 64 bits, then the limit is 16 exabytes.
2551.1Schristos
2561.1Schristos33. Does zlib have any security vulnerabilities?
2571.1Schristos
2581.1Schristos    The only one that we are aware of is potentially in gzprintf(). If zlib
2591.1Schristos    is compiled to use sprintf() or vsprintf(), then there is no protection
2601.1Schristos    against a buffer overflow of a 4K string space, other than the caller of
2611.1Schristos    gzprintf() assuring that the output will not exceed 4K. On the other
2621.1Schristos    hand, if zlib is compiled to use snprintf() or vsnprintf(), which should
2631.1Schristos    normally be the case, then there is no vulnerability. The ./configure
2641.1Schristos    script will display warnings if an insecure variation of sprintf() will
2651.1Schristos    be used by gzprintf(). Also the zlibCompileFlags() function will return
2661.1Schristos    information on what variant of sprintf() is used by gzprintf().
2671.1Schristos
2681.1Schristos    If you don't have snprintf() or vsnprintf() and would like one, you can
2691.1Schristos    find a portable implementation here:
2701.1Schristos
2711.1Schristos        http://www.ijs.si/software/snprintf/
2721.1Schristos
2731.1Schristos    Note that you should be using the most recent version of zlib. Versions
2741.1Schristos    1.1.3 and before were subject to a double-free vulnerability.
2751.1Schristos
2761.1Schristos34. Is there a Java version of zlib?
2771.1Schristos
2781.1Schristos    Probably what you want is to use zlib in Java. zlib is already included
2791.1Schristos    as part of the Java SDK in the java.util.zip package. If you really want
2801.1Schristos    a version of zlib written in the Java language, look on the zlib home
2811.1Schristos    page for links: http://www.zlib.org/
2821.1Schristos
2831.1Schristos35. I get this or that compiler or source-code scanner warning when I crank it
2841.1Schristos    up to maximally-pedantic. Can't you guys write proper code?
2851.1Schristos
2861.1Schristos    Many years ago, we gave up attempting to avoid warnings on every compiler
2871.1Schristos    in the universe. It just got to be a waste of time, and some compilers
2881.1Schristos    were downright silly. So now, we simply make sure that the code always
2891.1Schristos    works.
2901.1Schristos
2911.1Schristos36. Valgrind (or some similar memory access checker) says that deflate is
2921.1Schristos    performing a conditional jump that depends on an uninitialized value.
2931.1Schristos    Isn't that a bug?
2941.1Schristos
2951.1Schristos    No.  That is intentional for performance reasons, and the output of
2961.1Schristos    deflate is not affected.  This only started showing up recently since
2971.1Schristos    zlib 1.2.x uses malloc() by default for allocations, whereas earlier
2981.1Schristos    versions used calloc(), which zeros out the allocated memory.
2991.1Schristos
3001.1Schristos37. Will zlib read the (insert any ancient or arcane format here) compressed
3011.1Schristos    data format?
3021.1Schristos
3031.1Schristos    Probably not. Look in the comp.compression FAQ for pointers to various
3041.1Schristos    formats and associated software.
3051.1Schristos
3061.1Schristos38. How can I encrypt/decrypt zip files with zlib?
3071.1Schristos
3081.1Schristos    zlib doesn't support encryption. The original PKZIP encryption is very weak
3091.1Schristos    and can be broken with freely available programs. To get strong encryption,
3101.1Schristos    use GnuPG, http://www.gnupg.org/ , which already includes zlib compression.
3111.1Schristos    For PKZIP compatible "encryption", look at http://www.info-zip.org/
3121.1Schristos
3131.1Schristos39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
3141.1Schristos
3151.1Schristos    "gzip" is the gzip format, and "deflate" is the zlib format. They should
3161.1Schristos    probably have called the second one "zlib" instead to avoid confusion
3171.1Schristos    with the raw deflate compressed data format. While the HTTP 1.1 RFC 2616
3181.1Schristos    correctly points to the zlib specification in RFC 1950 for the "deflate"
3191.1Schristos    transfer encoding, there have been reports of servers and browsers that
3201.1Schristos    incorrectly produce or expect raw deflate data per the deflate
3211.1Schristos    specficiation in RFC 1951, most notably Microsoft. So even though the
3221.1Schristos    "deflate" transfer encoding using the zlib format would be the more
3231.1Schristos    efficient approach (and in fact exactly what the zlib format was designed
3241.1Schristos    for), using the "gzip" transfer encoding is probably more reliable due to
3251.1Schristos    an unfortunate choice of name on the part of the HTTP 1.1 authors.
3261.1Schristos
3271.1Schristos    Bottom line: use the gzip format for HTTP 1.1 encoding.
3281.1Schristos
3291.1Schristos40. Does zlib support the new "Deflate64" format introduced by PKWare?
3301.1Schristos
3311.1Schristos    No. PKWare has apparently decided to keep that format proprietary, since
3321.1Schristos    they have not documented it as they have previous compression formats.
3331.1Schristos    In any case, the compression improvements are so modest compared to other
3341.1Schristos    more modern approaches, that it's not worth the effort to implement.
3351.1Schristos
3361.1Schristos41. Can you please sign these lengthy legal documents and fax them back to us
3371.1Schristos    so that we can use your software in our product?
3381.1Schristos
3391.1Schristos    No. Go away. Shoo.
340