Module Name: src
Committed By: mrg
Date: Sat Dec 5 03:23:37 UTC 2009
Modified Files:
src/usr.bin/gzip: unbzip2.c
Log Message:
apply a change from Xin LI <[email protected]> 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.12 -r1.13 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.12 src/usr.bin/gzip/unbzip2.c:1.13
--- src/usr.bin/gzip/unbzip2.c:1.12 Sun Oct 11 05:17:20 2009
+++ src/usr.bin/gzip/unbzip2.c Sat Dec 5 03:23:37 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: unbzip2.c,v 1.12 2009/10/11 05:17:20 mrg Exp $ */
+/* $NetBSD: unbzip2.c,v 1.13 2009/12/05 03:23:37 mrg 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;