From owner-svn-src-head@FreeBSD.ORG Mon Nov 16 22:52:52 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 953CA1065679; Mon, 16 Nov 2009 22:52:52 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 84E318FC19; Mon, 16 Nov 2009 22:52:52 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nAGMqqrO083975; Mon, 16 Nov 2009 22:52:52 GMT (envelope-from delphij@svn.freebsd.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nAGMqqcx083973; Mon, 16 Nov 2009 22:52:52 GMT (envelope-from delphij@svn.freebsd.org) Message-Id: <200911162252.nAGMqqcx083973@svn.freebsd.org> From: Xin LI Date: Mon, 16 Nov 2009 22:52:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r199339 - head/usr.bin/gzip X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Nov 2009 22:52:52 -0000 Author: delphij Date: Mon Nov 16 22:52:52 2009 New Revision: 199339 URL: http://svn.freebsd.org/changeset/base/199339 Log: We should distinguish between a real truncated case and EOF after BZ_STREAM_END triggered re-init. Do it by introducing a new flag to represent the 'cold' case after bzip2 state is reinitialized. This fixes regression reported on -current@ as well as another one I found during twiddling with gzip. Reported by: swell.k gmail.com MFC after: 1 week Modified: head/usr.bin/gzip/unbzip2.c Modified: head/usr.bin/gzip/unbzip2.c ============================================================================== --- head/usr.bin/gzip/unbzip2.c Mon Nov 16 21:53:56 2009 (r199338) +++ head/usr.bin/gzip/unbzip2.c Mon Nov 16 22:52:52 2009 (r199339) @@ -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 @@ unbzip2(int in, int out, char *pre, size 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 @@ unbzip2(int in, int out, char *pre, size if (BZ2_bzDecompressEnd(&bzs) != BZ_OK || BZ2_bzDecompressInit(&bzs, 0, 0) != BZ_OK) maybe_errx("bzip2 re-init"); + cold = 1; ret = BZ_OK; } break;