bug-gzip, Below is a patch fix the bug. (Note: the patch is against 1.4, except that the source files were expanded to eliminate tabs.)
Mark --- gzip-1.4.c 2010-01-03 09:26:02.000000000 -0800 +++ gzip.c 2010-02-02 23:11:45.000000000 -0800 @@ -1239,6 +1239,7 @@ { uch flags; /* compression flags */ char magic[2]; /* magic header */ + int imagic0; /* first magic byte or EOF */ int imagic1; /* like magic[1], but can represent EOF */ ulg stamp; /* time stamp */ @@ -1246,12 +1247,14 @@ * premature end of file: use try_byte instead of get_byte. */ if (force && to_stdout) { - magic[0] = (char)try_byte(); + imagic0 = try_byte(); + magic[0] = (char) imagic0; imagic1 = try_byte (); magic[1] = (char) imagic1; /* If try_byte returned EOF, magic[1] == (char) EOF. */ } else { magic[0] = (char)get_byte(); + imagic0 = 0; if (magic[0]) { magic[1] = (char)get_byte(); imagic1 = 0; /* avoid lint warning */ @@ -1395,8 +1398,13 @@ } else if (force && to_stdout && !list) { /* pass input unchanged */ method = STORED; work = copy; - inptr = 0; + inptr--; last_member = 1; + if (imagic0 != EOF) { + write_buf(fileno(stdout), magic, 1); + bytes_in++; + bytes_out++; + } } if (method >= 0) return method; --- util-1.4.c 2010-01-03 09:26:02.000000000 -0800 +++ util.c 2010-02-02 23:25:31.000000000 -0800 @@ -44,21 +44,23 @@ /* =========================================================================== * Copy input to output unchanged: zcat == cat with --force. - * IN assertion: insize bytes have already been read in inbuf. + * IN assertion: insize bytes have already been read in inbuf and inptr bytes + * already processed or copied. */ int copy(in, out) int in, out; /* input and output file descriptors */ { errno = 0; - while (insize != 0 && (int)insize != -1) { - write_buf(out, (char*)inbuf, insize); - bytes_out += insize; + while (insize > inptr && (int)insize != -1) { + write_buf(out, (char*)inbuf + inptr, insize - inptr); + bytes_in += insize - inptr; + bytes_out += insize - inptr; insize = read_buffer (in, (char *) inbuf, INBUFSIZ); + inptr = 0; } if ((int)insize == -1) { read_error(); } - bytes_in = bytes_out; return OK; } gromit%