We should distinguish between a real truncated case and EOF after
BZ_STREAM_END triggered re-init. Do it by introducing a new flag to represent the 'cold' case after bzip2 state is reinitialized. This fixes regression reported on -current@ as well as another one I found during twiddling with gzip. Reported by: swell.k gmail.com MFC after: 1 week
This commit is contained in:
parent
4e38e56b0d
commit
adba2f7336
@ -36,7 +36,7 @@
|
|||||||
static off_t
|
static off_t
|
||||||
unbzip2(int in, int out, char *pre, size_t prelen, off_t *bytes_in)
|
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;
|
off_t bytes_out = 0;
|
||||||
bz_stream bzs;
|
bz_stream bzs;
|
||||||
static char *inbuf, *outbuf;
|
static char *inbuf, *outbuf;
|
||||||
@ -86,8 +86,18 @@ unbzip2(int in, int out, char *pre, size_t prelen, off_t *bytes_in)
|
|||||||
switch (ret) {
|
switch (ret) {
|
||||||
case BZ_STREAM_END:
|
case BZ_STREAM_END:
|
||||||
case BZ_OK:
|
case BZ_OK:
|
||||||
if (ret == BZ_OK && end_of_file)
|
if (ret == BZ_OK && end_of_file) {
|
||||||
maybe_err("read");
|
/*
|
||||||
|
* 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) {
|
if (!tflag && bzs.avail_out != BUFLEN) {
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
|
||||||
@ -100,6 +110,7 @@ unbzip2(int in, int out, char *pre, size_t prelen, off_t *bytes_in)
|
|||||||
if (BZ2_bzDecompressEnd(&bzs) != BZ_OK ||
|
if (BZ2_bzDecompressEnd(&bzs) != BZ_OK ||
|
||||||
BZ2_bzDecompressInit(&bzs, 0, 0) != BZ_OK)
|
BZ2_bzDecompressInit(&bzs, 0, 0) != BZ_OK)
|
||||||
maybe_errx("bzip2 re-init");
|
maybe_errx("bzip2 re-init");
|
||||||
|
cold = 1;
|
||||||
ret = BZ_OK;
|
ret = BZ_OK;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user