Skip to content

Commit

Permalink
Fix issue where bzip2 files containing multiple streams were being tr…
Browse files Browse the repository at this point in the history
…uncated

Thanks to Bill Herrin for pointing this out (#54)
  • Loading branch information
salcock committed Sep 18, 2023
1 parent 12f7d3c commit f0237b8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/ior-bzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct bz_t {
int outoffset;
io_t *parent;
enum err_t err;
uint8_t streamopen;
};

extern io_source_t bz_source;
Expand Down Expand Up @@ -72,7 +73,7 @@ DLLEXPORT io_t *bz_open(io_t *parent) {

BZ2_bzDecompressInit(&DATA(io)->strm, 0, /* Verbosity */
0); /* small */

DATA(io)->streamopen = 1;
return io;
}

Expand Down Expand Up @@ -114,7 +115,11 @@ static int64_t bz_read(io_t *io, void *buffer, int64_t len) {
DATA(io)->err = ERR_OK;
break;
case BZ_STREAM_END:
DATA(io)->err = ERR_EOF;
/* Stream is over, but there could be more stream to
* follow (e.g. if the file was compressed by pbzip2)
*/
BZ2_bzDecompressEnd(&DATA(io)->strm);
BZ2_bzDecompressInit(&DATA(io)->strm, 0, 0);
break;
default:
errno = EIO;
Expand All @@ -126,7 +131,9 @@ static int64_t bz_read(io_t *io, void *buffer, int64_t len) {
}

static void bz_close(io_t *io) {
BZ2_bzDecompressEnd(&DATA(io)->strm);
if (DATA(io)->streamopen) {
BZ2_bzDecompressEnd(&DATA(io)->strm);
}
wandio_destroy(DATA(io)->parent);
free(io->data);
free(io);
Expand Down

0 comments on commit f0237b8

Please sign in to comment.