Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Nov 2009 15:27:44 -0800
From:      Xin LI <delphij@delphij.net>
To:        d@delphij.net
Cc:        Anonymous <swell.k@gmail.com>, freebsd-current@FreeBSD.ORG, Xin LI <delphij@FreeBSD.ORG>, matthew green <mrg@eterna.com.au>
Subject:   Re: svn commit: r199066 - head/usr.bin/gzip
Message-ID:  <4AFDEB70.5080807@delphij.net>
In-Reply-To: <4AFDE27F.1070406@delphij.net>
References:  <200911090237.nA92b2m7005471__19254.880565177$1257734275$gmane$org@svn.freebsd.org> <867htvhygy.fsf@gmail.com> <4AFDDEA1.70900@delphij.net> <4AFDE27F.1070406@delphij.net>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------020506000801030506030104
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Xin LI wrote:
> Xin LI wrote:
>> Anonymous wrote:
>>> Xin LI <delphij@FreeBSD.org> writes:
>>>> Author: delphij
>>>> Date: Mon Nov  9 02:37:02 2009
>>>> New Revision: 199066
>>>> URL: http://svn.freebsd.org/changeset/base/199066
>>>>
>>>> Log:
>>>>   Apply a NetBSD fix (revision 1.12) to handle multi-session bzip2 files
>>>>   as created by pbzip2.
>>>>   
>>>>   Submitted by:	mrg (NetBSD.org)
>>>>   MFC after:	1 week
>>>>
>>>> Modified:
>>>>   head/usr.bin/gzip/unbzip2.c
>>>>
>>>     $ touch blah
>>>     $ bzip2 blah
>>>     $ gzip -d blah.bz2
>>>     gzip: read: No such file or directory
>>>     Exit 2
>>> Regression? Can you reproduce?
>> Yes, this is a regression (confirmed that this behavior is different
>> from bzip2 and a regression from 199065).  Thanks for your report and
>> I'll investigate what's happening.
> 
> I think the attached patch should fixed this issue.  Could you please test?

The previous fix has introduced an issue that revealed another bug as
well (gzip -d -c can't decompress large-ish input stream, i.e. something
like bzip2 -c ObsoleteFiles.inc | gunzip -d -c).  The proposed patch:

 * Set end_of_file flag if we hit a short read.  This usually saves one
read after the actual end of file.
 * Only bail out when BZ_OK and end_of_file and no output is given from
decompression engine.  This would fix the streaming issue.
 * Use maybe_errx() instead of maybe_err - We don't have a valid errno
at hand at the point we have received BZ_OK, and make the information
more meaningful.

Cheers,
- --
Xin LI <delphij@delphij.net>	http://www.delphij.net/
FreeBSD - The Power to Serve!	       Live free or die
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.13 (FreeBSD)

iEYEARECAAYFAkr963AACgkQi+vbBBjt66CqEwCffIgM9W25Tjdu2zlNGfarpKyS
oYwAoI+oVyjIdMdZo8VXN/TwfHhm0P2P
=zSGu
-----END PGP SIGNATURE-----

--------------020506000801030506030104
Content-Type: text/plain;
 name="gzip.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="gzip.diff"

Index: unbzip2.c
===================================================================
--- unbzip2.c	(revision 199258)
+++ unbzip2.c	(working copy)
@@ -71,7 +71,7 @@
 	                n = read(in, inbuf, BUFLEN);
 	                if (n < 0)
 	                        maybe_err("read");
-	                if (n == 0)
+	                if (n < BUFLEN)
 	                        end_of_file = 1;
 	                bzs.next_in = inbuf;
 	                bzs.avail_in = n;
@@ -86,8 +86,9 @@
 	        switch (ret) {
 	        case BZ_STREAM_END:
 	        case BZ_OK:
-	                if (ret == BZ_OK && end_of_file)
-	                        maybe_err("read");
+	                if (ret == BZ_OK && end_of_file &&
+			    bzs.avail_out == BUFLEN)
+	                        maybe_errx("truncated file");
 	                if (!tflag && bzs.avail_out != BUFLEN) {
 				ssize_t	n;
 

--------------020506000801030506030104--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4AFDEB70.5080807>