[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gzip --force bug
From: |
Mark Adler |
Subject: |
Re: gzip --force bug |
Date: |
Wed, 3 Feb 2010 18:52:16 -0800 |
On Feb 3, 2010, at 8:19 AM, Mark Adler wrote:
> Below is a patch to the patch.
>
> A test case will be forthcoming (I need to create a case that delicately
> crosses a buffer boundary). Once I get a test case working, you can push it.
Jim,
It turns out that is no condition in which the lack of the patch to the patch
causes a problem. So I have no test case for it. I will leave the patch to
the patch in nevertheless, since otherwise it still looks like a bug.
I fixed some other problems with how bytes_in is handled. An updated total
patch relative to 1.4 is below. This patch is final.
Mark
--- gzip-1.4.c 2010-01-03 09:26:02.000000000 -0800
+++ gzip.c 2010-02-03 18:41:08.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;
+ if (imagic1 != EOF)
+ inptr--;
last_member = 1;
+ if (imagic0 != EOF) {
+ write_buf(fileno(stdout), magic, 1);
+ bytes_out++;
+ }
}
if (method >= 0) return method;
--- util-1.4.c 2010-01-03 09:26:02.000000000 -0800
+++ util.c 2010-02-03 18:29:59.000000000 -0800
@@ -44,21 +44,25 @@
/* ===========================================================================
* 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 */
{
+ int got;
+
errno = 0;
- while (insize != 0 && (int)insize != -1) {
- write_buf(out, (char*)inbuf, insize);
- bytes_out += insize;
- insize = read_buffer (in, (char *) inbuf, INBUFSIZ);
- }
- if ((int)insize == -1) {
- read_error();
+ while (insize > inptr) {
+ write_buf(out, (char*)inbuf + inptr, insize - inptr);
+ bytes_out += insize - inptr;
+ got = read_buffer (in, (char *) inbuf, INBUFSIZ);
+ if (got == -1)
+ read_error();
+ bytes_in += got;
+ insize = (unsigned)got;
+ inptr = 0;
}
- bytes_in = bytes_out;
return OK;
}
- gzip --force bug, Mark Adler, 2010/02/02
- Re: gzip --force bug, Jim Meyering, 2010/02/03
- Re: gzip --force bug, Mark Adler, 2010/02/03
- Re: gzip --force bug, Jim Meyering, 2010/02/03
- Re: gzip --force bug, Mark Adler, 2010/02/03
- Re: gzip --force bug, Mark Adler, 2010/02/03
- Re: gzip --force bug, Mark Adler, 2010/02/03
- Re: gzip --force bug,
Mark Adler <=
- Re: gzip --force bug, Jim Meyering, 2010/02/04
- Re: gzip --force bug, Mark Adler, 2010/02/04
- Re: gzip --force bug, Jim Meyering, 2010/02/04
- gzip 1.4 warnings, Mark Adler, 2010/02/03