[Boost-bugs] [Boost C++ Libraries] #8165: basic_text_iprimitive loads garbage instead of throwing

Subject: [Boost-bugs] [Boost C++ Libraries] #8165: basic_text_iprimitive loads garbage instead of throwing
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-02-24 23:05:04


#8165: basic_text_iprimitive loads garbage instead of throwing
----------------------------------------------------------------+-----------
 Reporter: Louis Dionne <louis.dionne92@…> | Owner: ramey
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: serialization
  Version: Boost 1.53.0 | Severity: Problem
 Keywords: serialization archive_exception input_stream_error |
----------------------------------------------------------------+-----------
 Hi,

 When loading several objects from a text_iarchive, one can load one too
 many object without the archive throwing an exception. In such case, the
 last object loaded will contain garbage. If one tries to load yet another
 object, then an exception is thrown. Here is a minimal working example to
 show the issue:


 {{{
 #include <boost/archive/text_iarchive.hpp>
 #include <boost/archive/text_oarchive.hpp>
 #include <iostream>
 #include <sstream>


 int main() {
     std::stringstream ss;

     {
         boost::archive::text_oarchive oarchive(ss);
         char a = 'a', b = 'b';
         oarchive << a << b;
     }

     std::cout << "saved: \"" << ss.str() << "\"\n";

     {
         boost::archive::text_iarchive iarchive(ss);
         char a, b, garbage, will_fail;

         iarchive >> a;
         std::cout << "happily loaded a:\"" << a << "\"\n";

         iarchive >> b;
         std::cout << "happily loaded b:\"" << b << "\"\n";

         iarchive >> garbage;
         std::cout << "happily loaded garbage:\"" << garbage << "\"\n";

         try {
             iarchive >> will_fail;
         } catch (std::exception const& e) {
             std::cout << e.what();
             throw;
         }
     }
 }
 }}}


 Attached is a patch that seems to fix the problem (and removes some
 trailing white spaces from the sources). I also ran all of
 Boost.Serialization's unit tests with the fix and everything passes.

 Regards,

 Louis Dionne

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8165>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:12 UTC