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