boostorg/iostreams

Error reading multi-stream bzip2 files using bzip2_decompressor

gfrontera opened this issue · 1 comments

Some tools generate multi-stream bzip2 files in which several bzip2 data streams are concatenated end-to-end. Using the bzip2 executable extracts the file correctly. However, using the example code from the docs does not extract the whole content of the file.

The first call to decompress() after the stream is re-initialized (after finishing reading the first stream) returns BZ_DATA_ERROR_MAGIC. Then, the bzip2_error::check(result) throws an exception, and the following output is provided:

terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::iostreams::bzip2_error> >'
  what():  bzip2 error: iostream error

The file does contain the magic bytes at the beginning of each stream.

I have found that the boost::iostreams::detail::bzip2_decompressor_impl::filter(i1, i2, o1, o2, flush) method does not meet the postcondition requiring that either i1 == i2 or o1 == o2. This causes the failure when reading a multi-stream bzip2 file.