Module Name: src Committed By: snj Date: Wed Dec 9 04:58:15 UTC 2009
Modified Files: src/usr.bin/gzip [netbsd-5]: unbzip2.c Log Message: Pull up following revision(s) (requested by mrg in ticket #1182): usr.bin/gzip/unbzip2.c: revision 1.13 apply a change from Xin LI <delp...@delphij.net> to avoid problems when reading from pipes. introduced with the multi-part bz2 fixes. To generate a diff of this commit: cvs rdiff -u -r1.11.6.1 -r1.11.6.2 src/usr.bin/gzip/unbzip2.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/gzip/unbzip2.c diff -u src/usr.bin/gzip/unbzip2.c:1.11.6.1 src/usr.bin/gzip/unbzip2.c:1.11.6.2 --- src/usr.bin/gzip/unbzip2.c:1.11.6.1 Sun Nov 8 22:51:56 2009 +++ src/usr.bin/gzip/unbzip2.c Wed Dec 9 04:58:15 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: unbzip2.c,v 1.11.6.1 2009/11/08 22:51:56 snj Exp $ */ +/* $NetBSD: unbzip2.c,v 1.11.6.2 2009/12/09 04:58:15 snj Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -34,7 +34,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; @@ -84,8 +84,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; @@ -98,6 +108,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;