svn commit: r199066 - head/usr.bin/gzip
Xin LI
delphij at delphij.net
Sun Nov 15 10:17:23 UTC 2009
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 <delphij at delphij.net> http://www.delphij.net/
FreeBSD - The Power to Serve! Live free or die
-------------- next part --------------
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;
More information about the freebsd-current
mailing list