[Zlib-devel] zlib 1.2.3.6 available for testing

Török Edwin edwintorok at gmail.com
Mon Jan 18 11:06:21 EST 2010


On 01/18/2010 11:46 AM, Mark Adler wrote:
> On Jan 18, 2010, at 1:10 AM, Török Edwin wrote:
>   
>> Doesn't that introduce
>> incompatibilities when decompressing something compressed with another
>> version of zlib?
>>     
>
> No.  inflate is insensitive to some of the bits in those elements, and so of course those are the bits I vary randomly for each version.
>   

Thanks for the explanation.

I have looked through zlib.h, and noticed some inconsistencies:
"deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
   memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
   method). "

This doesn't mention that it can fail due to zlib version mismatch
(deflateInit does).
There may be more functions where Z_VERSION_ERROR is missing from the docs.
IMHO the documentation should list all possible error codes.

Some comments about gzdopen(). zlib.h says:
"The next call of gzclose on the returned gzFile will also close the file
descriptor fd, just like fclose(fdopen(fd), mode) closes the file descriptor
fd.  If you want to keep fd open, use gzdopen(dup(fd), mode).

gzdopen returns NULL if there was insufficient memory to allocate the
(de)compression state."

There are 3 issues here
1.  This says nothing about what happens with the file descriptor if
NULL was returned. It can be deduced that the file descriptor is not closed,
and a quick look at the implementation confirms this. IMHO this should
be documented.
2. gzdopen(dup(fd), mode) leaks the file descriptor returned by dup() if
gzdopen fails. I think this example should make it explicit
that you do need to save the duped fd to a variable.
3. gzdopen can return NULL if an invalid mode is specified, if
(de/in)flateInit2 fails, or if fdopen fails.
Not only if memory allocation fails. (deflateInit2 could fail due to a
zlib version mismatch, or something else.)
The documentation should mention this.

The attached patch suggests how to fix these 3 issues (but not the one
about Z_VERSION_ERROR above).

Best regards,
--Edwin
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch
URL: <http://madler.net/pipermail/zlib-devel_madler.net/attachments/20100118/ec7f145d/attachment.ksh>


More information about the Zlib-devel mailing list