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