Ticket #4257: binary_invalid_signature.diff

File binary_invalid_signature.diff, 1.3 KB (added by Gevorg Voskanyan <v_gevorg@…>, 12 years ago)

Proposed fix

  • basic_binary_iarchive.ipp

     
    1616#if defined(BOOST_NO_STDC_NAMESPACE)
    1717namespace std{
    1818    using ::memcpy;
     19    using ::strlen;
     20    using ::size_t;
    1921}
    2022#endif
    2123
     
    4850basic_binary_iarchive<Archive>::init(){
    4951    // read signature in an archive version independent manner
    5052    std::string file_signature;
    51     * this->This() >> file_signature;
     53    try {
     54        std::size_t l;
     55        this->This()->load(l);
     56        if(l == std::strlen(BOOST_ARCHIVE_SIGNATURE())) {
     57            // borland de-allocator fixup
     58            #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
     59            if(NULL != file_signature.data())
     60            #endif
     61                file_signature.resize(l);
     62            // note breaking a rule here - could be a problem on some platform
     63            if(0 < l)
     64                this->This()->load_binary(&(*file_signature.begin()), l);
     65        }
     66    }
     67    catch(archive_exception const &) {  // catch stream_error archive exceptions
     68        file_signature = "";   // will cause invalid_signature archive exception to be thrown below
     69    }
    5270    if(file_signature != BOOST_ARCHIVE_SIGNATURE())
    5371        boost::serialization::throw_exception(
    5472            archive_exception(archive_exception::invalid_signature)