[Zlib-devel] EOF detection in check_headers()

Mark Brown broonie at sirena.org.uk
Sun Oct 30 10:28:11 EST 2005


On Sun, Oct 30, 2005 at 11:28:55AM +0000, Mark Brown wrote:

> It turned out that this was happening because check_headers() was not
> flagging EOF when reading data - a patch fixing this is enclosed
> below.

There was also another case, where fread() would be called after EOF had
been reported:

--- zlib-1.2.3.orig/gzio.c	2005-10-30 10:56:39.000000000 +0000
+++ zlib-1.2.3/gzio.c	2005-10-30 10:55:36.000000000 +0000
@@ -301,6 +301,7 @@
         if (len) s->inbuf[0] = s->stream.next_in[0];
         errno = 0;
         len = (uInt)fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file);
+	if (len == 0) s->z_eof = 1;
         if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO;
         s->stream.avail_in += len;
         s->stream.next_in = s->inbuf;
@@ -436,7 +437,7 @@
                 s->stream.avail_out -= n;
                 s->stream.avail_in  -= n;
             }
-            if (s->stream.avail_out > 0) {
+            if (s->stream.avail_out > 0 && !feof(s->file)) {
                 s->stream.avail_out -=
                     (uInt)fread(next_out, 1, s->stream.avail_out, s->file);
             }

-- 
"You grabbed my hand and we fell into it, like a daydream - or a fever."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 307 bytes
Desc: Digital signature
URL: <http://madler.net/pipermail/zlib-devel_madler.net/attachments/20051030/98b52aea/attachment.sig>


More information about the Zlib-devel mailing list