Boost C++ Libraries: Ticket #5291: bzip2_decompressor does not work properly with a filtering_streambuf https://svn.boost.org/trac10/ticket/5291 <p> The revision 63057 of boost/iostreams/filter/bzip2.hpp seems to have broken the ability to use the bzip2 decompressor in a filtering streambuf. When I pass a stream into the buffer it throws data_error_magic. Stepping through the code I can see it correctly decode the zipped data, but then it continues to attempt to decode data even after eof is reached. </p> <p> Looking at the changes to bzip2_decompressor_impl I see the following issues: 1.) The function returns true even if _eof is set to true. This causes the "done" flag in the "Read" function in symmetric.hpp to be set to false, which causes the bzip2_decompressor_impl function to execute again, after EOL. 2.) On the second execution when _eof is set, the "close" function resets _eof to false, which can cause the function to throw the exception. </p> <p> In the specific instance I am using, my bzip compressed section is embedded in the middle of the stream, so src_begin won't equal src_end. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5291 Trac 1.4.3 anonymous Mon, 14 Mar 2011 16:34:52 GMT <link>https://svn.boost.org/trac10/ticket/5291#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5291#comment:1</guid> <description> <p> Can you provide a code sample that demonstrates the problem? Even better, look at the existing bzip2 tests in boost\libs\iostreams\test\bzip2_test.cpp and see if you can add a test case which demonstrates it. </p> </description> <category>Ticket</category> </item> <item> <author>chris.steenwyk@…</author> <pubDate>Thu, 17 Nov 2011 19:17:51 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/5291 https://svn.boost.org/trac10/ticket/5291 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">bzip2_test_patch</span> </li> </ul> <p> Patch file for libs/iostreams/test/bzip2_test.cpp </p> Ticket chris.steenwyk@… Thu, 17 Nov 2011 19:18:22 GMT <link>https://svn.boost.org/trac10/ticket/5291#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5291#comment:2</guid> <description> <p> Sorry it took so long. </p> <p> The code below works on boost 1.42 and generates an exception on 1.45. I have also attached a patch to add this test into the test file bzip2_test.cpp. </p> <pre class="wiki">#include &lt;string&gt; #include &lt;boost/iostreams/filter/bzip2.hpp&gt; #include &lt;boost/iostreams/filter/test.hpp&gt; #include &lt;boost/iostreams/filtering_stream.hpp&gt; std::vector&lt;char&gt; temp; std::string source( "This is test data" ); std::vector&lt;char&gt; sourceVector( source.begin(), source.end() ); std::vector&lt;char&gt; dest; // Write compressed source to temp boost::iostreams::filtering_streambuf&lt; boost::iostreams::output &gt; out; out.push( boost::iostreams::bzip2_compressor() ); out.push( boost::iostreams::back_inserter( temp ) ); boost::iostreams::copy( boost::make_iterator_range( source ), out ); // Add uncompressed source around the compressed source temp.insert( temp.begin(), source.begin(), source.end() ); temp.insert( temp.end(), source.begin(), source.end() ); // Read compressed data from temp into dest boost::iostreams::array_source inStr( &amp;temp[ source.length() ], temp.size() ); boost::iostreams::filtering_streambuf&lt; boost::iostreams::input &gt; in; in.push( boost::iostreams::bzip2_decompressor() ); in.push( inStr ); boost::iostreams::copy( in, boost::iostreams::back_inserter( dest ) ); </pre> </description> <category>Ticket</category> </item> <item> <author>vograno@…</author> <pubDate>Thu, 31 Jan 2013 23:10:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5291#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5291#comment:3</guid> <description> <p> I ran into the same problem. Boost version 1.49. Is there a workaround? Any alternative way to decompress bzip2? </p> </description> <category>Ticket</category> </item> <item> <author>Fred Baba <fred.baba@…></author> <pubDate>Mon, 01 Jul 2013 00:20:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5291#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5291#comment:4</guid> <description> <p> Same issue in Boost 1.53. </p> </description> <category>Ticket</category> </item> </channel> </rss>