Boost C++ Libraries: Ticket #8165: basic_text_iprimitive loads garbage instead of throwing https://svn.boost.org/trac10/ticket/8165 <p> Hi, </p> <p> 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: </p> <pre class="wiki">#include &lt;boost/archive/text_iarchive.hpp&gt; #include &lt;boost/archive/text_oarchive.hpp&gt; #include &lt;iostream&gt; #include &lt;sstream&gt; int main() { std::stringstream ss; { boost::archive::text_oarchive oarchive(ss); char a = 'a', b = 'b'; oarchive &lt;&lt; a &lt;&lt; b; } std::cout &lt;&lt; "saved: \"" &lt;&lt; ss.str() &lt;&lt; "\"\n"; { boost::archive::text_iarchive iarchive(ss); char a, b, garbage, will_fail; iarchive &gt;&gt; a; std::cout &lt;&lt; "happily loaded a:\"" &lt;&lt; a &lt;&lt; "\"\n"; iarchive &gt;&gt; b; std::cout &lt;&lt; "happily loaded b:\"" &lt;&lt; b &lt;&lt; "\"\n"; iarchive &gt;&gt; garbage; std::cout &lt;&lt; "happily loaded garbage:\"" &lt;&lt; garbage &lt;&lt; "\"\n"; try { iarchive &gt;&gt; will_fail; } catch (std::exception const&amp; e) { std::cout &lt;&lt; e.what(); throw; } } } </pre><p> 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. </p> <p> Regards, </p> <p> Louis Dionne </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8165 Trac 1.4.3 Louis Dionne Sun, 24 Feb 2013 23:09:57 GMT attachment set https://svn.boost.org/trac10/ticket/8165 https://svn.boost.org/trac10/ticket/8165 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">basic_text_iprimitive.diff</span> </li> </ul> <p> Patch for the described issue. </p> Ticket Louis Dionne Sun, 24 Feb 2013 23:13:46 GMT <link>https://svn.boost.org/trac10/ticket/8165#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8165#comment:1</guid> <description> <p> By the way, Chrome won't properly display the captcha to validate that you're a human when you upload a patch containing links. This caused some confusion on my side and I accidently double posted. Sorry! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Mon, 25 Feb 2013 20:23:30 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8165#comment:2 https://svn.boost.org/trac10/ticket/8165#comment:2 <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 anonymous Thu, 24 Oct 2013 06:38:18 GMT status, version changed; resolution deleted https://svn.boost.org/trac10/ticket/8165#comment:3 https://svn.boost.org/trac10/ticket/8165#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.53.0</span> → <span class="trac-field-new">Boost Development Trunk</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> This problem is not fixed at all. </p> <blockquote class="citation"> <blockquote> <p> if(! is.fail()){ </p> <blockquote> <p> is &gt;&gt; t; return; </p> </blockquote> <p> } </p> </blockquote> </blockquote> <p> above code is not changed to: </p> <blockquote class="citation"> <blockquote> <p> if(is &gt;&gt; t){ </p> <blockquote> <p> return; </p> </blockquote> <p> } </p> </blockquote> </blockquote> Ticket Robert Ramey Wed, 19 Feb 2014 21:14:25 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/8165#comment:4 https://svn.boost.org/trac10/ticket/8165#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> OK - I've checked in the change. </p> Ticket