|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r62965 - in trunk: boost/iostreams/filter libs/iostreams/src
From: steven_at_[hidden]
Date: 2010-06-14 22:52:44
Author: steven_watanabe
Date: 2010-06-14 22:52:42 EDT (Mon, 14 Jun 2010)
New Revision: 62965
URL: http://svn.boost.org/trac/boost/changeset/62965
Log:
Throw an exception on an unexpected end of file in bzip2_decompressor instead of going into an infinite loop. Fixes #2783.
Text files modified:
trunk/boost/iostreams/filter/bzip2.hpp | 5 ++++-
trunk/boost/iostreams/filter/test.hpp | 37 +++++++++++++++++++++++++++----------
trunk/libs/iostreams/src/bzip2.cpp | 12 ++++++++++++
3 files changed, 43 insertions(+), 11 deletions(-)
Modified: trunk/boost/iostreams/filter/bzip2.hpp
==============================================================================
--- trunk/boost/iostreams/filter/bzip2.hpp (original)
+++ trunk/boost/iostreams/filter/bzip2.hpp 2010-06-14 22:52:42 EDT (Mon, 14 Jun 2010)
@@ -166,6 +166,7 @@
void before( const char*& src_begin, const char* src_end,
char*& dest_begin, char* dest_end );
void after(const char*& src_begin, char*& dest_begin);
+ int check_end(const char* src_begin, const char* dest_begin);
int compress(int action);
int decompress();
void end(bool compress);
@@ -347,7 +348,7 @@
template<typename Alloc>
bool bzip2_decompressor_impl<Alloc>::filter
( const char*& src_begin, const char* src_end,
- char*& dest_begin, char* dest_end, bool /* flush */ )
+ char*& dest_begin, char* dest_end, bool flush )
{
if (!ready())
init();
@@ -355,6 +356,8 @@
return false;
before(src_begin, src_end, dest_begin, dest_end);
int result = decompress();
+ if(result == bzip2::ok && flush)
+ result = check_end(src_begin, dest_begin);
after(src_begin, dest_begin);
bzip2_error::check BOOST_PREVENT_MACRO_SUBSTITUTION(result);
return !(eof_ = result == bzip2::stream_end);
Modified: trunk/boost/iostreams/filter/test.hpp
==============================================================================
--- trunk/boost/iostreams/filter/test.hpp (original)
+++ trunk/boost/iostreams/filter/test.hpp 2010-06-14 22:52:42 EDT (Mon, 14 Jun 2010)
@@ -239,16 +239,33 @@
inc <= default_increment * 40;
inc += default_increment )
{
- array_source src(data.data(), data.data() + data.size());
- std::string temp;
- std::string dest;
- iostreams::copy(src, compose(out, non_blocking_sink(temp, inc)));
- iostreams::copy(
- compose(in, non_blocking_source(temp, inc)),
- iostreams::back_inserter(dest)
- );
- if (dest != data)
- return false;
+ {
+ array_source src(data.data(), data.data() + data.size());
+ std::string temp;
+ std::string dest;
+ iostreams::copy(src, compose(out, non_blocking_sink(temp, inc)));
+ iostreams::copy(
+ compose(in, non_blocking_source(temp, inc)),
+ iostreams::back_inserter(dest)
+ );
+ if (dest != data)
+ return false;
+ }
+ {
+ array_source src(data.data(), data.data() + data.size());
+ std::string temp;
+ std::string dest;
+ iostreams::copy(src, compose(out, non_blocking_sink(temp, inc)));
+ // truncate the file, this should not loop, it may throw
+ // std::ios_base::failure, which we swallow.
+ try {
+ temp.resize(temp.size() / 2);
+ iostreams::copy(
+ compose(in, non_blocking_source(temp, inc)),
+ iostreams::back_inserter(dest)
+ );
+ } catch(std::ios_base::failure&) {}
+ }
}
return true;
}
Modified: trunk/libs/iostreams/src/bzip2.cpp
==============================================================================
--- trunk/libs/iostreams/src/bzip2.cpp (original)
+++ trunk/libs/iostreams/src/bzip2.cpp 2010-06-14 22:52:42 EDT (Mon, 14 Jun 2010)
@@ -99,6 +99,18 @@
dest_begin = s->next_out;
}
+int bzip2_base::check_end(const char* src_begin, const char* dest_begin)
+{
+ bz_stream* s = static_cast<bz_stream*>(stream_);
+ if( src_begin == s->next_in &&
+ s->avail_in == 0 &&
+ dest_begin == s->next_out) {
+ return bzip2::unexpected_eof;
+ } else {
+ return bzip2::ok;
+ }
+}
+
void bzip2_base::end(bool compress)
{
if(!ready_) return;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk