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 Index: unbzip2.c =================================================================== --- unbzip2.c (revision 199284) +++ unbzip2.c (working copy) _at__at_ -36,7 +36,7 _at__at_ 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; _at__at_ -86,8 +86,18 _at__at_ 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; _at__at_ -100,6 +110,7 _at__at_ if (BZ2_bzDecompressEnd(&bzs) != BZ_OK || BZ2_bzDecompressInit(&bzs, 0, 0) != BZ_OK) maybe_errx("bzip2 re-init"); + cold = 1; ret = BZ_OK; } break;Received on Sun Nov 15 2009 - 09:17:23 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:58 UTC