svn commit: r200047 - stable/8/usr.bin/gzip
Xin LI
delphij at FreeBSD.org
Wed Dec 2 21:58:01 UTC 2009
Author: delphij
Date: Wed Dec 2 21:58:00 2009
New Revision: 200047
URL: http://svn.freebsd.org/changeset/base/200047
Log:
MFC r199066 + 199339:
Apply a NetBSD fix (revision 1.12) to handle multi-session bzip2 files
as created by pbzip2.
Modified:
stable/8/usr.bin/gzip/unbzip2.c
Directory Properties:
stable/8/usr.bin/gzip/ (props changed)
Modified: stable/8/usr.bin/gzip/unbzip2.c
==============================================================================
--- stable/8/usr.bin/gzip/unbzip2.c Wed Dec 2 21:22:10 2009 (r200046)
+++ stable/8/usr.bin/gzip/unbzip2.c Wed Dec 2 21:58:00 2009 (r200047)
@@ -1,4 +1,4 @@
-/* $NetBSD: unbzip2.c,v 1.11 2008/04/28 20:24:13 martin Exp $ */
+/* $NetBSD: unbzip2.c,v 1.12 2009/10/11 05:17:20 mrg Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -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;
@@ -64,7 +64,7 @@ unbzip2(int in, int out, char *pre, size
if (bytes_in)
*bytes_in = prelen;
- while (ret >= BZ_OK && ret != BZ_STREAM_END) {
+ while (ret == BZ_OK) {
if (bzs.avail_in == 0 && !end_of_file) {
ssize_t n;
@@ -86,9 +86,19 @@ 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 (!tflag) {
+ 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;
n = write(out, outbuf, BUFLEN - bzs.avail_out);
@@ -96,7 +106,14 @@ unbzip2(int in, int out, char *pre, size
maybe_err("write");
bytes_out += n;
}
- break;
+ if (ret == BZ_STREAM_END && !end_of_file) {
+ if (BZ2_bzDecompressEnd(&bzs) != BZ_OK ||
+ BZ2_bzDecompressInit(&bzs, 0, 0) != BZ_OK)
+ maybe_errx("bzip2 re-init");
+ cold = 1;
+ ret = BZ_OK;
+ }
+ break;
case BZ_DATA_ERROR:
maybe_warnx("bzip2 data integrity error");
@@ -109,7 +126,10 @@ unbzip2(int in, int out, char *pre, size
case BZ_MEM_ERROR:
maybe_warnx("bzip2 out of memory");
break;
-
+
+ default:
+ maybe_warnx("unknown bzip2 error: %d", ret);
+ break;
}
}
More information about the svn-src-stable
mailing list