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