Boost C++ Libraries: Ticket #4257: Improving invalid signature detection in binary iarchive https://svn.boost.org/trac10/ticket/4257 <p> Binary iarchive is supposed to throw invalid_signature archive_exception when the archive content doesn't start with the expected signature. However in some cases a different behavior is observed when trying to load from an invalid archive. For example, if the supposed signature size being read ends up a huge number (can easily happen trying to load from an arbitrary file not created with Boost.Serialization), the program spends a few seconds on line 111 of basic_binary_iprimitive.ipp (s.resize(l);) allocating a big chunk of memory to read the signature into, then tries to read that many bytes from the stream, which, assuming the file is not that large, reads less bytes than requested so it all ends up throwing archive_exception(stream_error) at basic_binary_iprimitive.hpp:164. Another example is when the 'signature size' being read happens to be a larger number still, then s.resize(l); throws std::bad_alloc when in fact the user would want to get archive_exception(invalid_signature) instead. </p> <p> Patch for archive/impl/basic_binary_iarchive.ipp against Boost 1.43 is attached which makes basic_binary_iarchive to consistently throw archive_exception(invalid_signature) when the archive content does not start with the expected signature. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4257 Trac 1.4.3 Gevorg Voskanyan <v_gevorg@…> Tue, 25 May 2010 16:17:29 GMT attachment set https://svn.boost.org/trac10/ticket/4257 https://svn.boost.org/trac10/ticket/4257 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">binary_invalid_signature.diff</span> </li> </ul> <p> Proposed fix </p> Ticket Gevorg Voskanyan <v_gevorg@…> Tue, 25 May 2010 16:18:34 GMT cc set https://svn.boost.org/trac10/ticket/4257#comment:1 https://svn.boost.org/trac10/ticket/4257#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">v_gevorg@…</span> added </li> </ul> Ticket Robert Ramey Mon, 31 May 2010 22:03:50 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4257#comment:2 https://svn.boost.org/trac10/ticket/4257#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> <p> I've inserted this patch into my own copy for testing. Looks good to me. This initiates the migration to trunk then to release. </p> <p> Robert Ramey </p> Ticket