xref: /netbsd-src/common/dist/zlib/FAQ (revision b175d1c2a0d8a7ee59df83b5ae5f0bd11632ced6)
1aaf4ece6Schristos
2aaf4ece6Schristos                Frequently Asked Questions about zlib
3aaf4ece6Schristos
4aaf4ece6Schristos
5aaf4ece6SchristosIf your question is not there, please check the zlib home page
6c3423655Schristoshttp://zlib.net/ which may have more recent information.
7*b175d1c2SchristosThe latest zlib FAQ is at http://zlib.net/zlib_faq.html
8aaf4ece6Schristos
9aaf4ece6Schristos
10aaf4ece6Schristos 1. Is zlib Y2K-compliant?
11aaf4ece6Schristos
12aaf4ece6Schristos    Yes. zlib doesn't handle dates.
13aaf4ece6Schristos
14aaf4ece6Schristos 2. Where can I get a Windows DLL version?
15aaf4ece6Schristos
16c3423655Schristos    The zlib sources can be compiled without change to produce a DLL.  See the
17*b175d1c2Schristos    file win32/DLL_FAQ.txt in the zlib distribution.
18aaf4ece6Schristos
19aaf4ece6Schristos 3. Where can I get a Visual Basic interface to zlib?
20aaf4ece6Schristos
21aaf4ece6Schristos    See
22c3423655Schristos        * http://marknelson.us/1997/01/01/zlib-engine/
23aaf4ece6Schristos        * win32/DLL_FAQ.txt in the zlib distribution
24aaf4ece6Schristos
25aaf4ece6Schristos 4. compress() returns Z_BUF_ERROR.
26aaf4ece6Schristos
27c3423655Schristos    Make sure that before the call of compress(), the length of the compressed
28c3423655Schristos    buffer is equal to the available size of the compressed buffer and not
29aaf4ece6Schristos    zero.  For Visual Basic, check that this parameter is passed by reference
30aaf4ece6Schristos    ("as any"), not by value ("as long").
31aaf4ece6Schristos
32aaf4ece6Schristos 5. deflate() or inflate() returns Z_BUF_ERROR.
33aaf4ece6Schristos
34c3423655Schristos    Before making the call, make sure that avail_in and avail_out are not zero.
35c3423655Schristos    When setting the parameter flush equal to Z_FINISH, also make sure that
36c3423655Schristos    avail_out is big enough to allow processing all pending input.  Note that a
37c3423655Schristos    Z_BUF_ERROR is not fatal--another call to deflate() or inflate() can be
38c3423655Schristos    made with more input or output space.  A Z_BUF_ERROR may in fact be
39c3423655Schristos    unavoidable depending on how the functions are used, since it is not
40c3423655Schristos    possible to tell whether or not there is more output pending when
41c3423655Schristos    strm.avail_out returns with zero.  See http://zlib.net/zlib_how.html for a
42c3423655Schristos    heavily annotated example.
43aaf4ece6Schristos
44aaf4ece6Schristos 6. Where's the zlib documentation (man pages, etc.)?
45aaf4ece6Schristos
46c3423655Schristos    It's in zlib.h .  Examples of zlib usage are in the files test/example.c
47c3423655Schristos    and test/minigzip.c, with more in examples/ .
48aaf4ece6Schristos
49aaf4ece6Schristos 7. Why don't you use GNU autoconf or libtool or ...?
50aaf4ece6Schristos
51c3423655Schristos    Because we would like to keep zlib as a very small and simple package.
52c3423655Schristos    zlib is rather portable and doesn't need much configuration.
53aaf4ece6Schristos
54aaf4ece6Schristos 8. I found a bug in zlib.
55aaf4ece6Schristos
56c3423655Schristos    Most of the time, such problems are due to an incorrect usage of zlib.
57c3423655Schristos    Please try to reproduce the problem with a small program and send the
58c3423655Schristos    corresponding source to us at zlib@gzip.org .  Do not send multi-megabyte
59c3423655Schristos    data files without prior agreement.
60aaf4ece6Schristos
61aaf4ece6Schristos 9. Why do I get "undefined reference to gzputc"?
62aaf4ece6Schristos
63aaf4ece6Schristos    If "make test" produces something like
64aaf4ece6Schristos
65aaf4ece6Schristos       example.o(.text+0x154): undefined reference to `gzputc'
66aaf4ece6Schristos
67aaf4ece6Schristos    check that you don't have old files libz.* in /usr/lib, /usr/local/lib or
68aaf4ece6Schristos    /usr/X11R6/lib. Remove any old versions, then do "make install".
69aaf4ece6Schristos
70aaf4ece6Schristos10. I need a Delphi interface to zlib.
71aaf4ece6Schristos
72aaf4ece6Schristos    See the contrib/delphi directory in the zlib distribution.
73aaf4ece6Schristos
74aaf4ece6Schristos11. Can zlib handle .zip archives?
75aaf4ece6Schristos
76aaf4ece6Schristos    Not by itself, no.  See the directory contrib/minizip in the zlib
77aaf4ece6Schristos    distribution.
78aaf4ece6Schristos
79aaf4ece6Schristos12. Can zlib handle .Z files?
80aaf4ece6Schristos
81aaf4ece6Schristos    No, sorry.  You have to spawn an uncompress or gunzip subprocess, or adapt
82aaf4ece6Schristos    the code of uncompress on your own.
83aaf4ece6Schristos
84aaf4ece6Schristos13. How can I make a Unix shared library?
85aaf4ece6Schristos
86c3423655Schristos    By default a shared (and a static) library is built for Unix.  So:
87c3423655Schristos
88c3423655Schristos    make distclean
89c3423655Schristos    ./configure
90aaf4ece6Schristos    make
91aaf4ece6Schristos
92aaf4ece6Schristos14. How do I install a shared zlib library on Unix?
93aaf4ece6Schristos
94aaf4ece6Schristos    After the above, then:
95aaf4ece6Schristos
96aaf4ece6Schristos    make install
97aaf4ece6Schristos
98aaf4ece6Schristos    However, many flavors of Unix come with a shared zlib already installed.
99aaf4ece6Schristos    Before going to the trouble of compiling a shared version of zlib and
100aaf4ece6Schristos    trying to install it, you may want to check if it's already there!  If you
101c3423655Schristos    can #include <zlib.h>, it's there.  The -lz option will probably link to
102c3423655Schristos    it.  You can check the version at the top of zlib.h or with the
103c3423655Schristos    ZLIB_VERSION symbol defined in zlib.h .
104aaf4ece6Schristos
105aaf4ece6Schristos15. I have a question about OttoPDF.
106aaf4ece6Schristos
107aaf4ece6Schristos    We are not the authors of OttoPDF. The real author is on the OttoPDF web
108aaf4ece6Schristos    site: Joel Hainley, jhainley@myndkryme.com.
109aaf4ece6Schristos
110aaf4ece6Schristos16. Can zlib decode Flate data in an Adobe PDF file?
111aaf4ece6Schristos
112c3423655Schristos    Yes. See http://www.pdflib.com/ . To modify PDF forms, see
113c3423655Schristos    http://sourceforge.net/projects/acroformtool/ .
114aaf4ece6Schristos
115aaf4ece6Schristos17. Why am I getting this "register_frame_info not found" error on Solaris?
116aaf4ece6Schristos
117aaf4ece6Schristos    After installing zlib 1.1.4 on Solaris 2.6, running applications using zlib
118aaf4ece6Schristos    generates an error such as:
119aaf4ece6Schristos
120aaf4ece6Schristos        ld.so.1: rpm: fatal: relocation error: file /usr/local/lib/libz.so:
121aaf4ece6Schristos        symbol __register_frame_info: referenced symbol not found
122aaf4ece6Schristos
123aaf4ece6Schristos    The symbol __register_frame_info is not part of zlib, it is generated by
124aaf4ece6Schristos    the C compiler (cc or gcc).  You must recompile applications using zlib
125aaf4ece6Schristos    which have this problem.  This problem is specific to Solaris.  See
126aaf4ece6Schristos    http://www.sunfreeware.com for Solaris versions of zlib and applications
127aaf4ece6Schristos    using zlib.
128aaf4ece6Schristos
129aaf4ece6Schristos18. Why does gzip give an error on a file I make with compress/deflate?
130aaf4ece6Schristos
131aaf4ece6Schristos    The compress and deflate functions produce data in the zlib format, which
132aaf4ece6Schristos    is different and incompatible with the gzip format.  The gz* functions in
133c3423655Schristos    zlib on the other hand use the gzip format.  Both the zlib and gzip formats
134c3423655Schristos    use the same compressed data format internally, but have different headers
135c3423655Schristos    and trailers around the compressed data.
136aaf4ece6Schristos
137aaf4ece6Schristos19. Ok, so why are there two different formats?
138aaf4ece6Schristos
139c3423655Schristos    The gzip format was designed to retain the directory information about a
140c3423655Schristos    single file, such as the name and last modification date.  The zlib format
141c3423655Schristos    on the other hand was designed for in-memory and communication channel
142c3423655Schristos    applications, and has a much more compact header and trailer and uses a
143c3423655Schristos    faster integrity check than gzip.
144aaf4ece6Schristos
145aaf4ece6Schristos20. Well that's nice, but how do I make a gzip file in memory?
146aaf4ece6Schristos
147aaf4ece6Schristos    You can request that deflate write the gzip format instead of the zlib
148c3423655Schristos    format using deflateInit2().  You can also request that inflate decode the
149c3423655Schristos    gzip format using inflateInit2().  Read zlib.h for more details.
150aaf4ece6Schristos
151aaf4ece6Schristos21. Is zlib thread-safe?
152aaf4ece6Schristos
153aaf4ece6Schristos    Yes.  However any library routines that zlib uses and any application-
154aaf4ece6Schristos    provided memory allocation routines must also be thread-safe.  zlib's gz*
155aaf4ece6Schristos    functions use stdio library routines, and most of zlib's functions use the
156c3423655Schristos    library memory allocation routines by default.  zlib's *Init* functions
157c3423655Schristos    allow for the application to provide custom memory allocation routines.
158aaf4ece6Schristos
159aaf4ece6Schristos    Of course, you should only operate on any given zlib or gzip stream from a
160aaf4ece6Schristos    single thread at a time.
161aaf4ece6Schristos
162aaf4ece6Schristos22. Can I use zlib in my commercial application?
163aaf4ece6Schristos
164aaf4ece6Schristos    Yes.  Please read the license in zlib.h.
165aaf4ece6Schristos
166aaf4ece6Schristos23. Is zlib under the GNU license?
167aaf4ece6Schristos
168aaf4ece6Schristos    No.  Please read the license in zlib.h.
169aaf4ece6Schristos
170aaf4ece6Schristos24. The license says that altered source versions must be "plainly marked". So
171aaf4ece6Schristos    what exactly do I need to do to meet that requirement?
172aaf4ece6Schristos
173aaf4ece6Schristos    You need to change the ZLIB_VERSION and ZLIB_VERNUM #defines in zlib.h.  In
174aaf4ece6Schristos    particular, the final version number needs to be changed to "f", and an
175aaf4ece6Schristos    identification string should be appended to ZLIB_VERSION.  Version numbers
176aaf4ece6Schristos    x.x.x.f are reserved for modifications to zlib by others than the zlib
177aaf4ece6Schristos    maintainers.  For example, if the version of the base zlib you are altering
178aaf4ece6Schristos    is "1.2.3.4", then in zlib.h you should change ZLIB_VERNUM to 0x123f, and
179aaf4ece6Schristos    ZLIB_VERSION to something like "1.2.3.f-zachary-mods-v3".  You can also
180aaf4ece6Schristos    update the version strings in deflate.c and inftrees.c.
181aaf4ece6Schristos
182aaf4ece6Schristos    For altered source distributions, you should also note the origin and
183aaf4ece6Schristos    nature of the changes in zlib.h, as well as in ChangeLog and README, along
184aaf4ece6Schristos    with the dates of the alterations.  The origin should include at least your
185aaf4ece6Schristos    name (or your company's name), and an email address to contact for help or
186aaf4ece6Schristos    issues with the library.
187aaf4ece6Schristos
188aaf4ece6Schristos    Note that distributing a compiled zlib library along with zlib.h and
189aaf4ece6Schristos    zconf.h is also a source distribution, and so you should change
190aaf4ece6Schristos    ZLIB_VERSION and ZLIB_VERNUM and note the origin and nature of the changes
191aaf4ece6Schristos    in zlib.h as you would for a full source distribution.
192aaf4ece6Schristos
193aaf4ece6Schristos25. Will zlib work on a big-endian or little-endian architecture, and can I
194aaf4ece6Schristos    exchange compressed data between them?
195aaf4ece6Schristos
196aaf4ece6Schristos    Yes and yes.
197aaf4ece6Schristos
198aaf4ece6Schristos26. Will zlib work on a 64-bit machine?
199aaf4ece6Schristos
200c3423655Schristos    Yes.  It has been tested on 64-bit machines, and has no dependence on any
201c3423655Schristos    data types being limited to 32-bits in length.  If you have any
202aaf4ece6Schristos    difficulties, please provide a complete problem report to zlib@gzip.org
203aaf4ece6Schristos
204aaf4ece6Schristos27. Will zlib decompress data from the PKWare Data Compression Library?
205aaf4ece6Schristos
206c3423655Schristos    No.  The PKWare DCL uses a completely different compressed data format than
207c3423655Schristos    does PKZIP and zlib.  However, you can look in zlib's contrib/blast
208aaf4ece6Schristos    directory for a possible solution to your problem.
209aaf4ece6Schristos
210aaf4ece6Schristos28. Can I access data randomly in a compressed stream?
211aaf4ece6Schristos
212c3423655Schristos    No, not without some preparation.  If when compressing you periodically use
213c3423655Schristos    Z_FULL_FLUSH, carefully write all the pending data at those points, and
214c3423655Schristos    keep an index of those locations, then you can start decompression at those
215c3423655Schristos    points.  You have to be careful to not use Z_FULL_FLUSH too often, since it
216c3423655Schristos    can significantly degrade compression.  Alternatively, you can scan a
217c3423655Schristos    deflate stream once to generate an index, and then use that index for
218c3423655Schristos    random access.  See examples/zran.c .
219aaf4ece6Schristos
220aaf4ece6Schristos29. Does zlib work on MVS, OS/390, CICS, etc.?
221aaf4ece6Schristos
222c3423655Schristos    It has in the past, but we have not heard of any recent evidence.  There
223c3423655Schristos    were working ports of zlib 1.1.4 to MVS, but those links no longer work.
224c3423655Schristos    If you know of recent, successful applications of zlib on these operating
225c3423655Schristos    systems, please let us know.  Thanks.
226aaf4ece6Schristos
227c3423655Schristos30. Is there some simpler, easier to read version of inflate I can look at to
228c3423655Schristos    understand the deflate format?
229aaf4ece6Schristos
230aaf4ece6Schristos    First off, you should read RFC 1951.  Second, yes.  Look in zlib's
231aaf4ece6Schristos    contrib/puff directory.
232aaf4ece6Schristos
233aaf4ece6Schristos31. Does zlib infringe on any patents?
234aaf4ece6Schristos
235aaf4ece6Schristos    As far as we know, no.  In fact, that was originally the whole point behind
236aaf4ece6Schristos    zlib.  Look here for some more information:
237aaf4ece6Schristos
238aaf4ece6Schristos    http://www.gzip.org/#faq11
239aaf4ece6Schristos
240aaf4ece6Schristos32. Can zlib work with greater than 4 GB of data?
241aaf4ece6Schristos
242aaf4ece6Schristos    Yes.  inflate() and deflate() will process any amount of data correctly.
243aaf4ece6Schristos    Each call of inflate() or deflate() is limited to input and output chunks
244aaf4ece6Schristos    of the maximum value that can be stored in the compiler's "unsigned int"
245aaf4ece6Schristos    type, but there is no limit to the number of chunks.  Note however that the
246aaf4ece6Schristos    strm.total_in and strm_total_out counters may be limited to 4 GB.  These
247aaf4ece6Schristos    counters are provided as a convenience and are not used internally by
248aaf4ece6Schristos    inflate() or deflate().  The application can easily set up its own counters
249aaf4ece6Schristos    updated after each call of inflate() or deflate() to count beyond 4 GB.
250aaf4ece6Schristos    compress() and uncompress() may be limited to 4 GB, since they operate in a
251aaf4ece6Schristos    single call.  gzseek() and gztell() may be limited to 4 GB depending on how
252aaf4ece6Schristos    zlib is compiled.  See the zlibCompileFlags() function in zlib.h.
253aaf4ece6Schristos
254c3423655Schristos    The word "may" appears several times above since there is a 4 GB limit only
255c3423655Schristos    if the compiler's "long" type is 32 bits.  If the compiler's "long" type is
256c3423655Schristos    64 bits, then the limit is 16 exabytes.
257aaf4ece6Schristos
258aaf4ece6Schristos33. Does zlib have any security vulnerabilities?
259aaf4ece6Schristos
260c3423655Schristos    The only one that we are aware of is potentially in gzprintf().  If zlib is
261c3423655Schristos    compiled to use sprintf() or vsprintf(), then there is no protection
262c3423655Schristos    against a buffer overflow of an 8K string space (or other value as set by
263c3423655Schristos    gzbuffer()), other than the caller of gzprintf() assuring that the output
264c3423655Schristos    will not exceed 8K.  On the other hand, if zlib is compiled to use
265c3423655Schristos    snprintf() or vsnprintf(), which should normally be the case, then there is
266c3423655Schristos    no vulnerability.  The ./configure script will display warnings if an
267c3423655Schristos    insecure variation of sprintf() will be used by gzprintf().  Also the
268c3423655Schristos    zlibCompileFlags() function will return information on what variant of
269c3423655Schristos    sprintf() is used by gzprintf().
270aaf4ece6Schristos
271aaf4ece6Schristos    If you don't have snprintf() or vsnprintf() and would like one, you can
272aaf4ece6Schristos    find a portable implementation here:
273aaf4ece6Schristos
274aaf4ece6Schristos        http://www.ijs.si/software/snprintf/
275aaf4ece6Schristos
276aaf4ece6Schristos    Note that you should be using the most recent version of zlib.  Versions
277c3423655Schristos    1.1.3 and before were subject to a double-free vulnerability, and versions
278c3423655Schristos    1.2.1 and 1.2.2 were subject to an access exception when decompressing
279c3423655Schristos    invalid compressed data.
280aaf4ece6Schristos
281aaf4ece6Schristos34. Is there a Java version of zlib?
282aaf4ece6Schristos
283aaf4ece6Schristos    Probably what you want is to use zlib in Java. zlib is already included
284aaf4ece6Schristos    as part of the Java SDK in the java.util.zip package. If you really want
285aaf4ece6Schristos    a version of zlib written in the Java language, look on the zlib home
286c3423655Schristos    page for links: http://zlib.net/ .
287aaf4ece6Schristos
288aaf4ece6Schristos35. I get this or that compiler or source-code scanner warning when I crank it
289aaf4ece6Schristos    up to maximally-pedantic. Can't you guys write proper code?
290aaf4ece6Schristos
291aaf4ece6Schristos    Many years ago, we gave up attempting to avoid warnings on every compiler
292aaf4ece6Schristos    in the universe.  It just got to be a waste of time, and some compilers
293c3423655Schristos    were downright silly as well as contradicted each other.  So now, we simply
294c3423655Schristos    make sure that the code always works.
295aaf4ece6Schristos
296aaf4ece6Schristos36. Valgrind (or some similar memory access checker) says that deflate is
297aaf4ece6Schristos    performing a conditional jump that depends on an uninitialized value.
298aaf4ece6Schristos    Isn't that a bug?
299aaf4ece6Schristos
300c3423655Schristos    No.  That is intentional for performance reasons, and the output of deflate
301c3423655Schristos    is not affected.  This only started showing up recently since zlib 1.2.x
302c3423655Schristos    uses malloc() by default for allocations, whereas earlier versions used
303c3423655Schristos    calloc(), which zeros out the allocated memory.  Even though the code was
304c3423655Schristos    correct, versions 1.2.4 and later was changed to not stimulate these
305c3423655Schristos    checkers.
306aaf4ece6Schristos
307aaf4ece6Schristos37. Will zlib read the (insert any ancient or arcane format here) compressed
308aaf4ece6Schristos    data format?
309aaf4ece6Schristos
310aaf4ece6Schristos    Probably not. Look in the comp.compression FAQ for pointers to various
311aaf4ece6Schristos    formats and associated software.
312aaf4ece6Schristos
313aaf4ece6Schristos38. How can I encrypt/decrypt zip files with zlib?
314aaf4ece6Schristos
315c3423655Schristos    zlib doesn't support encryption.  The original PKZIP encryption is very
316c3423655Schristos    weak and can be broken with freely available programs.  To get strong
317c3423655Schristos    encryption, use GnuPG, http://www.gnupg.org/ , which already includes zlib
318c3423655Schristos    compression.  For PKZIP compatible "encryption", look at
319c3423655Schristos    http://www.info-zip.org/
320aaf4ece6Schristos
321aaf4ece6Schristos39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
322aaf4ece6Schristos
323aaf4ece6Schristos    "gzip" is the gzip format, and "deflate" is the zlib format.  They should
324c3423655Schristos    probably have called the second one "zlib" instead to avoid confusion with
325c3423655Schristos    the raw deflate compressed data format.  While the HTTP 1.1 RFC 2616
326aaf4ece6Schristos    correctly points to the zlib specification in RFC 1950 for the "deflate"
327aaf4ece6Schristos    transfer encoding, there have been reports of servers and browsers that
328aaf4ece6Schristos    incorrectly produce or expect raw deflate data per the deflate
329c3423655Schristos    specification in RFC 1951, most notably Microsoft.  So even though the
330aaf4ece6Schristos    "deflate" transfer encoding using the zlib format would be the more
331aaf4ece6Schristos    efficient approach (and in fact exactly what the zlib format was designed
332aaf4ece6Schristos    for), using the "gzip" transfer encoding is probably more reliable due to
333aaf4ece6Schristos    an unfortunate choice of name on the part of the HTTP 1.1 authors.
334aaf4ece6Schristos
335aaf4ece6Schristos    Bottom line: use the gzip format for HTTP 1.1 encoding.
336aaf4ece6Schristos
337aaf4ece6Schristos40. Does zlib support the new "Deflate64" format introduced by PKWare?
338aaf4ece6Schristos
339aaf4ece6Schristos    No.  PKWare has apparently decided to keep that format proprietary, since
340c3423655Schristos    they have not documented it as they have previous compression formats.  In
341c3423655Schristos    any case, the compression improvements are so modest compared to other more
342c3423655Schristos    modern approaches, that it's not worth the effort to implement.
343aaf4ece6Schristos
344c3423655Schristos41. I'm having a problem with the zip functions in zlib, can you help?
345c3423655Schristos
346c3423655Schristos    There are no zip functions in zlib.  You are probably using minizip by
347c3423655Schristos    Giles Vollant, which is found in the contrib directory of zlib.  It is not
348c3423655Schristos    part of zlib.  In fact none of the stuff in contrib is part of zlib.  The
349c3423655Schristos    files in there are not supported by the zlib authors.  You need to contact
350c3423655Schristos    the authors of the respective contribution for help.
351c3423655Schristos
352c3423655Schristos42. The match.asm code in contrib is under the GNU General Public License.
353c3423655Schristos    Since it's part of zlib, doesn't that mean that all of zlib falls under the
354c3423655Schristos    GNU GPL?
355c3423655Schristos
356c3423655Schristos    No.  The files in contrib are not part of zlib.  They were contributed by
357c3423655Schristos    other authors and are provided as a convenience to the user within the zlib
358c3423655Schristos    distribution.  Each item in contrib has its own license.
359c3423655Schristos
360c3423655Schristos43. Is zlib subject to export controls?  What is its ECCN?
361c3423655Schristos
362c3423655Schristos    zlib is not subject to export controls, and so is classified as EAR99.
363c3423655Schristos
364c3423655Schristos44. Can you please sign these lengthy legal documents and fax them back to us
365aaf4ece6Schristos    so that we can use your software in our product?
366aaf4ece6Schristos
367aaf4ece6Schristos    No. Go away. Shoo.
368