cannam@128: 
cannam@128:                 Frequently Asked Questions about zlib
cannam@128: 
cannam@128: 
cannam@128: If your question is not there, please check the zlib home page
cannam@128: http://zlib.net/ which may have more recent information.
cannam@128: The lastest zlib FAQ is at http://zlib.net/zlib_faq.html
cannam@128: 
cannam@128: 
cannam@128:  1. Is zlib Y2K-compliant?
cannam@128: 
cannam@128:     Yes. zlib doesn't handle dates.
cannam@128: 
cannam@128:  2. Where can I get a Windows DLL version?
cannam@128: 
cannam@128:     The zlib sources can be compiled without change to produce a DLL.  See the
cannam@128:     file win32/DLL_FAQ.txt in the zlib distribution.  Pointers to the
cannam@128:     precompiled DLL are found in the zlib web site at http://zlib.net/ .
cannam@128: 
cannam@128:  3. Where can I get a Visual Basic interface to zlib?
cannam@128: 
cannam@128:     See
cannam@128:         * http://marknelson.us/1997/01/01/zlib-engine/
cannam@128:         * win32/DLL_FAQ.txt in the zlib distribution
cannam@128: 
cannam@128:  4. compress() returns Z_BUF_ERROR.
cannam@128: 
cannam@128:     Make sure that before the call of compress(), the length of the compressed
cannam@128:     buffer is equal to the available size of the compressed buffer and not
cannam@128:     zero.  For Visual Basic, check that this parameter is passed by reference
cannam@128:     ("as any"), not by value ("as long").
cannam@128: 
cannam@128:  5. deflate() or inflate() returns Z_BUF_ERROR.
cannam@128: 
cannam@128:     Before making the call, make sure that avail_in and avail_out are not zero.
cannam@128:     When setting the parameter flush equal to Z_FINISH, also make sure that
cannam@128:     avail_out is big enough to allow processing all pending input.  Note that a
cannam@128:     Z_BUF_ERROR is not fatal--another call to deflate() or inflate() can be
cannam@128:     made with more input or output space.  A Z_BUF_ERROR may in fact be
cannam@128:     unavoidable depending on how the functions are used, since it is not
cannam@128:     possible to tell whether or not there is more output pending when
cannam@128:     strm.avail_out returns with zero.  See http://zlib.net/zlib_how.html for a
cannam@128:     heavily annotated example.
cannam@128: 
cannam@128:  6. Where's the zlib documentation (man pages, etc.)?
cannam@128: 
cannam@128:     It's in zlib.h .  Examples of zlib usage are in the files test/example.c
cannam@128:     and test/minigzip.c, with more in examples/ .
cannam@128: 
cannam@128:  7. Why don't you use GNU autoconf or libtool or ...?
cannam@128: 
cannam@128:     Because we would like to keep zlib as a very small and simple package.
cannam@128:     zlib is rather portable and doesn't need much configuration.
cannam@128: 
cannam@128:  8. I found a bug in zlib.
cannam@128: 
cannam@128:     Most of the time, such problems are due to an incorrect usage of zlib.
cannam@128:     Please try to reproduce the problem with a small program and send the
cannam@128:     corresponding source to us at zlib@gzip.org .  Do not send multi-megabyte
cannam@128:     data files without prior agreement.
cannam@128: 
cannam@128:  9. Why do I get "undefined reference to gzputc"?
cannam@128: 
cannam@128:     If "make test" produces something like
cannam@128: 
cannam@128:        example.o(.text+0x154): undefined reference to `gzputc'
cannam@128: 
cannam@128:     check that you don't have old files libz.* in /usr/lib, /usr/local/lib or
cannam@128:     /usr/X11R6/lib. Remove any old versions, then do "make install".
cannam@128: 
cannam@128: 10. I need a Delphi interface to zlib.
cannam@128: 
cannam@128:     See the contrib/delphi directory in the zlib distribution.
cannam@128: 
cannam@128: 11. Can zlib handle .zip archives?
cannam@128: 
cannam@128:     Not by itself, no.  See the directory contrib/minizip in the zlib
cannam@128:     distribution.
cannam@128: 
cannam@128: 12. Can zlib handle .Z files?
cannam@128: 
cannam@128:     No, sorry.  You have to spawn an uncompress or gunzip subprocess, or adapt
cannam@128:     the code of uncompress on your own.
cannam@128: 
cannam@128: 13. How can I make a Unix shared library?
cannam@128: 
cannam@128:     By default a shared (and a static) library is built for Unix.  So:
cannam@128: 
cannam@128:     make distclean
cannam@128:     ./configure
cannam@128:     make
cannam@128: 
cannam@128: 14. How do I install a shared zlib library on Unix?
cannam@128: 
cannam@128:     After the above, then:
cannam@128: 
cannam@128:     make install
cannam@128: 
cannam@128:     However, many flavors of Unix come with a shared zlib already installed.
cannam@128:     Before going to the trouble of compiling a shared version of zlib and
cannam@128:     trying to install it, you may want to check if it's already there!  If you
cannam@128:     can #include <zlib.h>, it's there.  The -lz option will probably link to
cannam@128:     it.  You can check the version at the top of zlib.h or with the
cannam@128:     ZLIB_VERSION symbol defined in zlib.h .
cannam@128: 
cannam@128: 15. I have a question about OttoPDF.
cannam@128: 
cannam@128:     We are not the authors of OttoPDF. The real author is on the OttoPDF web
cannam@128:     site: Joel Hainley, jhainley@myndkryme.com.
cannam@128: 
cannam@128: 16. Can zlib decode Flate data in an Adobe PDF file?
cannam@128: 
cannam@128:     Yes. See http://www.pdflib.com/ . To modify PDF forms, see
cannam@128:     http://sourceforge.net/projects/acroformtool/ .
cannam@128: 
cannam@128: 17. Why am I getting this "register_frame_info not found" error on Solaris?
cannam@128: 
cannam@128:     After installing zlib 1.1.4 on Solaris 2.6, running applications using zlib
cannam@128:     generates an error such as:
cannam@128: 
cannam@128:         ld.so.1: rpm: fatal: relocation error: file /usr/local/lib/libz.so:
cannam@128:         symbol __register_frame_info: referenced symbol not found
cannam@128: 
cannam@128:     The symbol __register_frame_info is not part of zlib, it is generated by
cannam@128:     the C compiler (cc or gcc).  You must recompile applications using zlib
cannam@128:     which have this problem.  This problem is specific to Solaris.  See
cannam@128:     http://www.sunfreeware.com for Solaris versions of zlib and applications
cannam@128:     using zlib.
cannam@128: 
cannam@128: 18. Why does gzip give an error on a file I make with compress/deflate?
cannam@128: 
cannam@128:     The compress and deflate functions produce data in the zlib format, which
cannam@128:     is different and incompatible with the gzip format.  The gz* functions in
cannam@128:     zlib on the other hand use the gzip format.  Both the zlib and gzip formats
cannam@128:     use the same compressed data format internally, but have different headers
cannam@128:     and trailers around the compressed data.
cannam@128: 
cannam@128: 19. Ok, so why are there two different formats?
cannam@128: 
cannam@128:     The gzip format was designed to retain the directory information about a
cannam@128:     single file, such as the name and last modification date.  The zlib format
cannam@128:     on the other hand was designed for in-memory and communication channel
cannam@128:     applications, and has a much more compact header and trailer and uses a
cannam@128:     faster integrity check than gzip.
cannam@128: 
cannam@128: 20. Well that's nice, but how do I make a gzip file in memory?
cannam@128: 
cannam@128:     You can request that deflate write the gzip format instead of the zlib
cannam@128:     format using deflateInit2().  You can also request that inflate decode the
cannam@128:     gzip format using inflateInit2().  Read zlib.h for more details.
cannam@128: 
cannam@128: 21. Is zlib thread-safe?
cannam@128: 
cannam@128:     Yes.  However any library routines that zlib uses and any application-
cannam@128:     provided memory allocation routines must also be thread-safe.  zlib's gz*
cannam@128:     functions use stdio library routines, and most of zlib's functions use the
cannam@128:     library memory allocation routines by default.  zlib's *Init* functions
cannam@128:     allow for the application to provide custom memory allocation routines.
cannam@128: 
cannam@128:     Of course, you should only operate on any given zlib or gzip stream from a
cannam@128:     single thread at a time.
cannam@128: 
cannam@128: 22. Can I use zlib in my commercial application?
cannam@128: 
cannam@128:     Yes.  Please read the license in zlib.h.
cannam@128: 
cannam@128: 23. Is zlib under the GNU license?
cannam@128: 
cannam@128:     No.  Please read the license in zlib.h.
cannam@128: 
cannam@128: 24. The license says that altered source versions must be "plainly marked". So
cannam@128:     what exactly do I need to do to meet that requirement?
cannam@128: 
cannam@128:     You need to change the ZLIB_VERSION and ZLIB_VERNUM #defines in zlib.h.  In
cannam@128:     particular, the final version number needs to be changed to "f", and an
cannam@128:     identification string should be appended to ZLIB_VERSION.  Version numbers
cannam@128:     x.x.x.f are reserved for modifications to zlib by others than the zlib
cannam@128:     maintainers.  For example, if the version of the base zlib you are altering
cannam@128:     is "1.2.3.4", then in zlib.h you should change ZLIB_VERNUM to 0x123f, and
cannam@128:     ZLIB_VERSION to something like "1.2.3.f-zachary-mods-v3".  You can also
cannam@128:     update the version strings in deflate.c and inftrees.c.
cannam@128: 
cannam@128:     For altered source distributions, you should also note the origin and
cannam@128:     nature of the changes in zlib.h, as well as in ChangeLog and README, along
cannam@128:     with the dates of the alterations.  The origin should include at least your
cannam@128:     name (or your company's name), and an email address to contact for help or
cannam@128:     issues with the library.
cannam@128: 
cannam@128:     Note that distributing a compiled zlib library along with zlib.h and
cannam@128:     zconf.h is also a source distribution, and so you should change
cannam@128:     ZLIB_VERSION and ZLIB_VERNUM and note the origin and nature of the changes
cannam@128:     in zlib.h as you would for a full source distribution.
cannam@128: 
cannam@128: 25. Will zlib work on a big-endian or little-endian architecture, and can I
cannam@128:     exchange compressed data between them?
cannam@128: 
cannam@128:     Yes and yes.
cannam@128: 
cannam@128: 26. Will zlib work on a 64-bit machine?
cannam@128: 
cannam@128:     Yes.  It has been tested on 64-bit machines, and has no dependence on any
cannam@128:     data types being limited to 32-bits in length.  If you have any
cannam@128:     difficulties, please provide a complete problem report to zlib@gzip.org
cannam@128: 
cannam@128: 27. Will zlib decompress data from the PKWare Data Compression Library?
cannam@128: 
cannam@128:     No.  The PKWare DCL uses a completely different compressed data format than
cannam@128:     does PKZIP and zlib.  However, you can look in zlib's contrib/blast
cannam@128:     directory for a possible solution to your problem.
cannam@128: 
cannam@128: 28. Can I access data randomly in a compressed stream?
cannam@128: 
cannam@128:     No, not without some preparation.  If when compressing you periodically use
cannam@128:     Z_FULL_FLUSH, carefully write all the pending data at those points, and
cannam@128:     keep an index of those locations, then you can start decompression at those
cannam@128:     points.  You have to be careful to not use Z_FULL_FLUSH too often, since it
cannam@128:     can significantly degrade compression.  Alternatively, you can scan a
cannam@128:     deflate stream once to generate an index, and then use that index for
cannam@128:     random access.  See examples/zran.c .
cannam@128: 
cannam@128: 29. Does zlib work on MVS, OS/390, CICS, etc.?
cannam@128: 
cannam@128:     It has in the past, but we have not heard of any recent evidence.  There
cannam@128:     were working ports of zlib 1.1.4 to MVS, but those links no longer work.
cannam@128:     If you know of recent, successful applications of zlib on these operating
cannam@128:     systems, please let us know.  Thanks.
cannam@128: 
cannam@128: 30. Is there some simpler, easier to read version of inflate I can look at to
cannam@128:     understand the deflate format?
cannam@128: 
cannam@128:     First off, you should read RFC 1951.  Second, yes.  Look in zlib's
cannam@128:     contrib/puff directory.
cannam@128: 
cannam@128: 31. Does zlib infringe on any patents?
cannam@128: 
cannam@128:     As far as we know, no.  In fact, that was originally the whole point behind
cannam@128:     zlib.  Look here for some more information:
cannam@128: 
cannam@128:     http://www.gzip.org/#faq11
cannam@128: 
cannam@128: 32. Can zlib work with greater than 4 GB of data?
cannam@128: 
cannam@128:     Yes.  inflate() and deflate() will process any amount of data correctly.
cannam@128:     Each call of inflate() or deflate() is limited to input and output chunks
cannam@128:     of the maximum value that can be stored in the compiler's "unsigned int"
cannam@128:     type, but there is no limit to the number of chunks.  Note however that the
cannam@128:     strm.total_in and strm_total_out counters may be limited to 4 GB.  These
cannam@128:     counters are provided as a convenience and are not used internally by
cannam@128:     inflate() or deflate().  The application can easily set up its own counters
cannam@128:     updated after each call of inflate() or deflate() to count beyond 4 GB.
cannam@128:     compress() and uncompress() may be limited to 4 GB, since they operate in a
cannam@128:     single call.  gzseek() and gztell() may be limited to 4 GB depending on how
cannam@128:     zlib is compiled.  See the zlibCompileFlags() function in zlib.h.
cannam@128: 
cannam@128:     The word "may" appears several times above since there is a 4 GB limit only
cannam@128:     if the compiler's "long" type is 32 bits.  If the compiler's "long" type is
cannam@128:     64 bits, then the limit is 16 exabytes.
cannam@128: 
cannam@128: 33. Does zlib have any security vulnerabilities?
cannam@128: 
cannam@128:     The only one that we are aware of is potentially in gzprintf().  If zlib is
cannam@128:     compiled to use sprintf() or vsprintf(), then there is no protection
cannam@128:     against a buffer overflow of an 8K string space (or other value as set by
cannam@128:     gzbuffer()), other than the caller of gzprintf() assuring that the output
cannam@128:     will not exceed 8K.  On the other hand, if zlib is compiled to use
cannam@128:     snprintf() or vsnprintf(), which should normally be the case, then there is
cannam@128:     no vulnerability.  The ./configure script will display warnings if an
cannam@128:     insecure variation of sprintf() will be used by gzprintf().  Also the
cannam@128:     zlibCompileFlags() function will return information on what variant of
cannam@128:     sprintf() is used by gzprintf().
cannam@128: 
cannam@128:     If you don't have snprintf() or vsnprintf() and would like one, you can
cannam@128:     find a portable implementation here:
cannam@128: 
cannam@128:         http://www.ijs.si/software/snprintf/
cannam@128: 
cannam@128:     Note that you should be using the most recent version of zlib.  Versions
cannam@128:     1.1.3 and before were subject to a double-free vulnerability, and versions
cannam@128:     1.2.1 and 1.2.2 were subject to an access exception when decompressing
cannam@128:     invalid compressed data.
cannam@128: 
cannam@128: 34. Is there a Java version of zlib?
cannam@128: 
cannam@128:     Probably what you want is to use zlib in Java. zlib is already included
cannam@128:     as part of the Java SDK in the java.util.zip package. If you really want
cannam@128:     a version of zlib written in the Java language, look on the zlib home
cannam@128:     page for links: http://zlib.net/ .
cannam@128: 
cannam@128: 35. I get this or that compiler or source-code scanner warning when I crank it
cannam@128:     up to maximally-pedantic. Can't you guys write proper code?
cannam@128: 
cannam@128:     Many years ago, we gave up attempting to avoid warnings on every compiler
cannam@128:     in the universe.  It just got to be a waste of time, and some compilers
cannam@128:     were downright silly as well as contradicted each other.  So now, we simply
cannam@128:     make sure that the code always works.
cannam@128: 
cannam@128: 36. Valgrind (or some similar memory access checker) says that deflate is
cannam@128:     performing a conditional jump that depends on an uninitialized value.
cannam@128:     Isn't that a bug?
cannam@128: 
cannam@128:     No.  That is intentional for performance reasons, and the output of deflate
cannam@128:     is not affected.  This only started showing up recently since zlib 1.2.x
cannam@128:     uses malloc() by default for allocations, whereas earlier versions used
cannam@128:     calloc(), which zeros out the allocated memory.  Even though the code was
cannam@128:     correct, versions 1.2.4 and later was changed to not stimulate these
cannam@128:     checkers.
cannam@128: 
cannam@128: 37. Will zlib read the (insert any ancient or arcane format here) compressed
cannam@128:     data format?
cannam@128: 
cannam@128:     Probably not. Look in the comp.compression FAQ for pointers to various
cannam@128:     formats and associated software.
cannam@128: 
cannam@128: 38. How can I encrypt/decrypt zip files with zlib?
cannam@128: 
cannam@128:     zlib doesn't support encryption.  The original PKZIP encryption is very
cannam@128:     weak and can be broken with freely available programs.  To get strong
cannam@128:     encryption, use GnuPG, http://www.gnupg.org/ , which already includes zlib
cannam@128:     compression.  For PKZIP compatible "encryption", look at
cannam@128:     http://www.info-zip.org/
cannam@128: 
cannam@128: 39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
cannam@128: 
cannam@128:     "gzip" is the gzip format, and "deflate" is the zlib format.  They should
cannam@128:     probably have called the second one "zlib" instead to avoid confusion with
cannam@128:     the raw deflate compressed data format.  While the HTTP 1.1 RFC 2616
cannam@128:     correctly points to the zlib specification in RFC 1950 for the "deflate"
cannam@128:     transfer encoding, there have been reports of servers and browsers that
cannam@128:     incorrectly produce or expect raw deflate data per the deflate
cannam@128:     specification in RFC 1951, most notably Microsoft.  So even though the
cannam@128:     "deflate" transfer encoding using the zlib format would be the more
cannam@128:     efficient approach (and in fact exactly what the zlib format was designed
cannam@128:     for), using the "gzip" transfer encoding is probably more reliable due to
cannam@128:     an unfortunate choice of name on the part of the HTTP 1.1 authors.
cannam@128: 
cannam@128:     Bottom line: use the gzip format for HTTP 1.1 encoding.
cannam@128: 
cannam@128: 40. Does zlib support the new "Deflate64" format introduced by PKWare?
cannam@128: 
cannam@128:     No.  PKWare has apparently decided to keep that format proprietary, since
cannam@128:     they have not documented it as they have previous compression formats.  In
cannam@128:     any case, the compression improvements are so modest compared to other more
cannam@128:     modern approaches, that it's not worth the effort to implement.
cannam@128: 
cannam@128: 41. I'm having a problem with the zip functions in zlib, can you help?
cannam@128: 
cannam@128:     There are no zip functions in zlib.  You are probably using minizip by
cannam@128:     Giles Vollant, which is found in the contrib directory of zlib.  It is not
cannam@128:     part of zlib.  In fact none of the stuff in contrib is part of zlib.  The
cannam@128:     files in there are not supported by the zlib authors.  You need to contact
cannam@128:     the authors of the respective contribution for help.
cannam@128: 
cannam@128: 42. The match.asm code in contrib is under the GNU General Public License.
cannam@128:     Since it's part of zlib, doesn't that mean that all of zlib falls under the
cannam@128:     GNU GPL?
cannam@128: 
cannam@128:     No.  The files in contrib are not part of zlib.  They were contributed by
cannam@128:     other authors and are provided as a convenience to the user within the zlib
cannam@128:     distribution.  Each item in contrib has its own license.
cannam@128: 
cannam@128: 43. Is zlib subject to export controls?  What is its ECCN?
cannam@128: 
cannam@128:     zlib is not subject to export controls, and so is classified as EAR99.
cannam@128: 
cannam@128: 44. Can you please sign these lengthy legal documents and fax them back to us
cannam@128:     so that we can use your software in our product?
cannam@128: 
cannam@128:     No. Go away. Shoo.