Opened 10 years ago

Closed 9 years ago

#8165 closed Bugs (fixed)

basic_text_iprimitive loads garbage instead of throwing

Reported by: Louis Dionne <louis.dionne92@…> Owned by: Robert Ramey
Milestone: To Be Determined Component: serialization
Version: Boost Development Trunk Severity: Problem
Keywords: serialization archive_exception input_stream_error Cc:

Description

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

Attachments (1)

basic_text_iprimitive.diff (2.0 KB ) - added by Louis Dionne 10 years ago.
Patch for the described issue.

Download all attachments as: .zip

Change History (5)

by Louis Dionne, 10 years ago

Attachment: basic_text_iprimitive.diff added

Patch for the described issue.

comment:1 by Louis Dionne, 10 years ago

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!

comment:2 by Robert Ramey, 10 years ago

Resolution: fixed
Status: newclosed

comment:3 by anonymous, 9 years ago

Resolution: fixed
Status: closedreopened
Version: Boost 1.53.0Boost Development Trunk

This problem is not fixed at all.

if(! is.fail()){

is >> t; return;

}

above code is not changed to:

if(is >> t){

return;

}

comment:4 by Robert Ramey, 9 years ago

Resolution: fixed
Status: reopenedclosed

OK - I've checked in the change.

Note: See TracTickets for help on using tickets.