From owner-freebsd-current@FreeBSD.ORG Sun Nov 15 10:17:23 2009 Return-Path: Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 127E1106566B for ; Sun, 15 Nov 2009 10:17:23 +0000 (UTC) (envelope-from delphij@delphij.net) Received: from tarsier.geekcn.org (delphij-pt.tunnel.tserv2.fmt.ipv6.he.net [IPv6:2001:470:1f03:2c9::2]) by mx1.freebsd.org (Postfix) with ESMTP id 943008FC12 for ; Sun, 15 Nov 2009 10:17:22 +0000 (UTC) Received: from localhost (tarsier.geekcn.org [211.166.10.233]) by tarsier.geekcn.org (Postfix) with ESMTP id 48BBE55CD9B5; Sun, 15 Nov 2009 18:17:21 +0800 (CST) X-Virus-Scanned: amavisd-new at geekcn.org Received: from tarsier.geekcn.org ([211.166.10.233]) by localhost (mail.geekcn.org [211.166.10.233]) (amavisd-new, port 10024) with ESMTP id fICMgfeN5NT4; Sun, 15 Nov 2009 18:17:13 +0800 (CST) Received: from delta.delphij.net (c-69-181-136-105.hsd1.ca.comcast.net [69.181.136.105]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by tarsier.geekcn.org (Postfix) with ESMTPSA id 1ABDC55CD9AB; Sun, 15 Nov 2009 18:17:11 +0800 (CST) DomainKey-Signature: a=rsa-sha1; s=default; d=delphij.net; c=nofws; q=dns; h=message-id:date:from:reply-to:organization:user-agent: mime-version:to:cc:subject:references:in-reply-to: x-enigmail-version:openpgp:content-type; b=pC/Yhz782cth5W7K6CNyCeD1ZPoWiPL1YWOR51JaSk2O9afb/M33obkXk1jguZwak 1eqjy1Zy/WRWTMzB+iUrg== Message-ID: <4AFFD525.9030300@delphij.net> Date: Sun, 15 Nov 2009 02:17:09 -0800 From: Xin LI Organization: The Geek China Organization User-Agent: Thunderbird 2.0.0.23 (X11/20091022) MIME-Version: 1.0 To: d@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> In-Reply-To: <4AFF8BE9.9000003@delphij.net> X-Enigmail-Version: 0.95.7 OpenPGP: id=18EDEBA0; url=http://www.delphij.net/delphij.asc Content-Type: multipart/mixed; boundary="------------070201060108000702020102" Cc: Anonymous , freebsd-current@FreeBSD.ORG, matthew green , Jilles Tjoelker Subject: Re: svn commit: r199066 - head/usr.bin/gzip X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: d@delphij.net List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Nov 2009 10:17:23 -0000 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 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--