[Zlib-devel] EOF detection in check_headers()

Mark Brown broonie at sirena.org.uk
Sun Oct 30 06:28:55 EST 2005


Mike Hommey <mh at glandium.org> reported that when reading from stdin on a
Unix system it would sometimes take a couple of control+Ds before
gzread() would return.  It turned out that this was happening because
check_headers() was not flagging EOF when reading data - a patch fixing
this is enclosed below.

Mike provided the following test program:

#include <zlib.h>

int main(void) {
	gzFile fd;
	char buffer[256];
	fd = gzdopen(dup(0), "rb");
	while(gzread(fd, buffer, 256));
	gzclose(fd);
	return 0;
}

--- 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;

-- 
"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/2019591f/attachment.sig>


More information about the Zlib-devel mailing list