Date: Sun, 15 Nov 2009 02:17:09 -0800 From: Xin LI <delphij@delphij.net> To: d@delphij.net Cc: Anonymous <swell.k@gmail.com>, freebsd-current@FreeBSD.ORG, matthew green <mrg@eterna.com.au>, Jilles Tjoelker <jilles@stack.nl> Subject: Re: svn commit: r199066 - head/usr.bin/gzip Message-ID: <4AFFD525.9030300@delphij.net> In-Reply-To: <4AFF8BE9.9000003@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> <4AFDEB70.5080807@delphij.net> <20091114130524.GA35115@stack.nl> <4AFF8BE9.9000003@delphij.net>
next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. --------------070201060108000702020102 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hi, Here is an updated version of the patch. I believe it fixed all raised issues. This version of patch employs a simple state bit that gets set when we hit a bzip2 end-of-stream symbol, and, if we got BZ_OK && end_of_file in the immediately subsequent cycle, consider it as Ok (turn the state machine back to BZ_STREAM_END so we exit normally). Each successful BZ_STREAM_END || BZ_OK case reset the cold state. Tested against empty bz2 file and pipe case. Cheers, -- Xin LI <delphij@delphij.net> http://www.delphij.net/ FreeBSD - The Power to Serve! Live free or die --------------070201060108000702020102 Content-Type: text/plain; name="gzip.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="gzip.diff" Index: unbzip2.c =================================================================== --- unbzip2.c (revision 199284) +++ unbzip2.c (working copy) @@ -36,7 +36,7 @@ static off_t unbzip2(int in, int out, char *pre, size_t prelen, off_t *bytes_in) { - int ret, end_of_file; + int ret, end_of_file, cold = 0; off_t bytes_out = 0; bz_stream bzs; static char *inbuf, *outbuf; @@ -86,8 +86,18 @@ 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) { + /* + * If we hit this after a stream end, consider + * it as the end of the whole file and don't + * bail out. + */ + if (cold == 1) + ret = BZ_STREAM_END; + else + maybe_errx("truncated file"); + } + cold = 0; if (!tflag && bzs.avail_out != BUFLEN) { ssize_t n; @@ -100,6 +110,7 @@ if (BZ2_bzDecompressEnd(&bzs) != BZ_OK || BZ2_bzDecompressInit(&bzs, 0, 0) != BZ_OK) maybe_errx("bzip2 re-init"); + cold = 1; ret = BZ_OK; } break; --------------070201060108000702020102--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4AFFD525.9030300>