Boost C++ Libraries: Ticket #5237: filtering_ostream produce incorrect empty files with gzip_compressor and other filters https://svn.boost.org/trac10/ticket/5237 <p> The attached program should produce an empty gzip file, using the gzip_compressor: </p> <pre class="wiki">int main() { using namespace boost::iostreams; filtering_ostream os; os.push(boost::iostreams::gzip_compressor()); os.push(boost::iostreams::file_sink("emptyGzipBug.txt.gz")); } </pre><p> The resulting file is not a gzip file: </p> <pre class="wiki">$ hexdump emptyGzipBug.txt.gz 0000000 0003 0000002 $ zcat testGzipEmpty.txt.gz zcat: testGzipEmpty.txt.gz: not in gzip format $ </pre><p> A workaround is to manually force an empty write into the stack of components with something like this: </p> <pre class="wiki"> char dummy = 'b'; os.component&lt;gzip_compressor&gt;(0)-&gt;write(*os.component&lt;file_sink&gt;(1), &amp;dummy, 0); </pre><p> The problem seems to affect all versions, including Boost 1.46.0 </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5237 Trac 1.4.3 anonymous Thu, 10 Nov 2011 01:10:43 GMT <link>https://svn.boost.org/trac10/ticket/5237#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5237#comment:1</guid> <description> <p> I've noticed this too in Boost 1.44.0. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Davin</dc:creator> <pubDate>Fri, 06 Jan 2012 20:24:41 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5237#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5237#comment:2</guid> <description> <p> Same issue in 1.47.0 and 1.48.0. </p> <p> You can patch boost/iostreams/filter/gzip.hpp, at line 251, insert the following two lines: </p> <pre class="wiki">if (!(flags_ &amp; f_header_done)) write(snk, 0, 0); </pre><p> If nothing has been written, calling write with no content will generate a proper empty gzip file. This is preferable to having a zero-length file for two reasons. First, it is consistent with the bzip2 filter to create a proper empty compressed file rather than a zero-length file. Second, zcat won't subsequently barf with a "unexpected end of file" error. </p> <p> Hope it helps. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 24 Aug 2012 10:38:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5237#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5237#comment:3</guid> <description> <p> Verified with 1.48.0 as well. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 29 Oct 2012 05:33:04 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5237#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5237#comment:4</guid> <description> <p> Thank you. This works for my situation. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>mefyl</dc:creator> <pubDate>Fri, 20 Sep 2013 13:05:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5237#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5237#comment:5</guid> <description> <p> This bug has been reported 3 years ago, an apparently working patch has been submitted almost two years ago and yet the bug is still present in Boost 1.53. With all due respect, I expect more from a high standard library such as Boost. </p> </description> <category>Ticket</category> </item> <item> <author>Come Raczy <come.raczy@…></author> <pubDate>Fri, 20 Sep 2013 13:52:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5237#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5237#comment:6</guid> <description> <p> and also present in boost 1.54 </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 10 Dec 2013 03:44:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5237#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5237#comment:7</guid> <description> <p> Still present in 1.55, perhaps someone thinks this is a feature. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 12 Nov 2014 13:38:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5237#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5237#comment:8</guid> <description> <p> This is ridiculous. I cannot imagine how this ever got accepted - was there no test suite for the GZip compression/decompression? Surely there are some tests for data round-tripping correctly, and a zero-length stream is an obvious case to include. Or does the decompressor silently ignore broken streams? </p> </description> <category>Ticket</category> </item> <item> <author>tiwoc@…</author> <pubDate>Thu, 27 Aug 2015 17:18:31 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/5237#comment:9 https://svn.boost.org/trac10/ticket/5237#comment:9 <ul> <li><strong>cc</strong> <span class="trac-author">tiwoc@…</span> added </li> </ul> <p> This is still present in 1.59.0. We now have invalid data in a production database :( </p> Ticket anonymous Wed, 02 Sep 2015 01:48:34 GMT <link>https://svn.boost.org/trac10/ticket/5237#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5237#comment:10</guid> <description> <p> Fixed in commit <a class="ext-link" href="https://github.com/boostorg/iostreams/commit/b8db28c0ac42cb40fd78de45ac1217f196e3af4f"><span class="icon">​</span>b8db28c0ac42cb40fd78de45ac1217f196e3af4f</a> in branch develop. Tested on msvc 10 and 14, gcc 4.4.7 and 4.9.1, and clang 3.4.2. </p> <p> I used the suggested fix, calling write() from within close(), except it was necessary to make a small change to write() so that gzip_compressor can be composed with a device or filter that does not support write(). </p> <p> Test case added. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 02 Sep 2015 01:49:20 GMT</pubDate> <title>version changed https://svn.boost.org/trac10/ticket/5237#comment:11 https://svn.boost.org/trac10/ticket/5237#comment:11 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.44.0</span> → <span class="trac-field-new">Boost 1.60.0</span> </li> </ul> Ticket tiwoc@… Wed, 02 Sep 2015 07:54:18 GMT <link>https://svn.boost.org/trac10/ticket/5237#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5237#comment:12</guid> <description> <p> That's great, thank you! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Jonathan Turkanis</dc:creator> <pubDate>Thu, 03 Sep 2015 16:56:50 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5237#comment:13 https://svn.boost.org/trac10/ticket/5237#comment:13 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket xiaopeifenng@… Thu, 23 Feb 2017 09:43:10 GMT <link>https://svn.boost.org/trac10/ticket/5237#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5237#comment:14</guid> <description> <p> also present in 1.55 </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 23 Feb 2017 12:09:12 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5237#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5237#comment:15</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/5237#comment:14" title="Comment 14">xiaopeifenng@…</a>: </p> <blockquote class="citation"> <p> also present in 1.55 </p> </blockquote> <p> Please upgrade Boost. This has been fixed in 1.60.0 as written above. </p> </description> <category>Ticket</category> </item> </channel> </rss>