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