Boost C++ Libraries: Ticket #7301: Inconsistent use of load_/save_override for serialized file signature https://svn.boost.org/trac10/ticket/7301 <p> basic_binary_oarchive.ipp::39 writes the file signature like this: </p> <ul><li>this-&gt;This() &lt;&lt; file_signature; </li></ul><p> Which if you're using your own binary_oarchive subclass to do custom serialization, ends up using your save_override(std::string&amp;, int) function to write the signature. </p> <p> However, basic_binary_iarchive.ipp::55 reads the file signature like so: std::size_t l; this-&gt;This()-&gt;load(l); if(l == std::strlen(BOOST_ARCHIVE_SIGNATURE())) { ... file_signature.resize(l); if(0 &lt; l){ ... this-&gt;This()-&gt;load_binary(&amp;(*file_signature.begin()), l); } } </p> <p> which does not make use of your load_override(std::string&amp;, int) function. Therefore if you change how strings are written, you get an invalid signature exception on deserialization. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7301 Trac 1.4.3 Paul Barba <paul.barba@…> Wed, 29 Aug 2012 14:30:54 GMT <link>https://svn.boost.org/trac10/ticket/7301#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7301#comment:1</guid> <description> <p> Sorry about the formatting, basic_binary_iarchive.ipp::55 is </p> <pre class="wiki">std::size_t l; this-&gt;This()-&gt;load(l); if(l == std::strlen(BOOST_ARCHIVE_SIGNATURE())) { ... file_signature.resize(l); if(0 &lt; l){ ... this-&gt;This()-&gt;load_binary(&amp;(*file_signature.begin()), l); } } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Wed, 29 Aug 2012 16:08:19 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/7301#comment:2 https://svn.boost.org/trac10/ticket/7301#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> and your suggested patch is ...? </p> <p> Robert Ramey </p> Ticket Paul Barba <paul.barba@…> Wed, 29 Aug 2012 16:21:41 GMT <link>https://svn.boost.org/trac10/ticket/7301#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7301#comment:3</guid> <description> <p> Well, you could just read the signature in basic_binary_iarchive.ipp like you write it: </p> <pre class="wiki">this-&gt;This() &gt;&gt; file_signature; </pre><p> But I'm guessing the code was changed because that causes problems in some test case involving an invalid file? So rather than handling signatures with the user overloaded string functions, you could just do the saving of the signature string manually as well, something like the following in init() in basic_binary_oarchive.ipp: </p> <pre class="wiki">std::size_t l = file_signature.size() this-&gt;This()-&gt;save(l); this-&gt;This()-&gt;save_binary(file_signature, l); </pre> </description> <category>Ticket</category> </item> <item> <author>Paul Barba <paul.barba@…></author> <pubDate>Wed, 29 Aug 2012 16:43:42 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7301#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7301#comment:4</guid> <description> <p> To add context, I went back and looked to see why a former colleague had overridden save_string() to begin with: Basically he switched the size_t for an unsigned int to induce x32/x64 compatibility into the binaries (the wisdom and correctness of such an operation being lengthy and off-topic.) In that sense supporting the load_override is preferable in that you retain the option of writing more portable string functions. However, since the goal of the binary archives is explicitly not 32/64 bit portability, it doesn't strike me as critical that that be supported here, only that the overrides be consistently used or ignored. Thus the first option is nicer in that judicious overrides can be used to overcome portability restraints, but I suspect there's a reason I don't know about that it's not done that way. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Wed, 19 Feb 2014 21:16:52 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7301#comment:5 https://svn.boost.org/trac10/ticket/7301#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> I checked in this change </p> <pre class="wiki">this-&gt;This() &gt;&gt; file_signature; </pre> Ticket