Opened 10 years ago

Last modified 9 years ago

#7240 new Patches

serialization backward compatibility issue with class_id_type attribute

Reported by: ggagniard@… Owned by: Robert Ramey
Milestone: To Be Determined Component: serialization
Version: Boost 1.50.0 Severity: Showstopper
Keywords: Cc:

Description

There is a backward compatibility issue in current boost::serialization around the class_id_type attribute.

It is actually impossible to read binary archives written with boost 1.39 (format 5) with a boost release > 1.43.

For instance, with boost 1.47.0 :

test_serialization: /home/ggagniard/dev/boost-1.47.0.bug/include/boost/archive/basic_archive.hpp:116: boost::archive::class_id_type::class_id_type(int): Assertion `t_ <= boost::integer_traits<base_type>::const_max' failed.

Please note that the same error still occurs with boost 1.50.0, the current stable release.

After having a look at the class_id_type serialization in binary archives, I think I found the culprit :

In boost/archive/basic_binary_iarchive.hpp :

    void load_override(class_id_type & t, int version){
        library_version_type lvt = this->get_library_version();
        if(boost::archive::library_version_type(7) < lvt){
            this->detail_common_iarchive::load_override(t, version);
        }
        else
        if(boost::archive::library_version_type(6) < lvt){
            int_least16_t x=0;
            * this->This() >> x;
            t = boost::archive::class_id_type(x);
        }
        else{
            int x=0;
            * this->This() >> x;
            t = boost::archive::class_id_type(x);
        }
    }

Here, archives whose version <= 6 get their class_id_type read as an int ...

However, in boost 1.43 (format 7) :

    void load_override(class_id_type & t, int){
        // upto 32K classes
        int_least16_t x=0;
        * this->This() >> x;
        t = class_id_type(x);
    }

It is clear than any library version <= 7 have their class_id_type serialized as a int_least16_t, so the current load_override method is incorrect for versions <= 6 ...

Attachments (1)

boost_serialization_fix147.patch (1.7 KB ) - added by ggagniard@… 10 years ago.
Proposed patch on boost 1.47 (should apply on 1.50 too)

Download all attachments as: .zip

Change History (3)

by ggagniard@…, 10 years ago

Proposed patch on boost 1.47 (should apply on 1.50 too)

comment:1 by ggagniard@…, 10 years ago

The proposed patch simply removes the special case for version 7 and reads class_id_type as an int_least16_t for any version <= 7, which was the behaviour in previous boost releases.

comment:2 by ggagniard@…, 9 years ago

Severity: RegressionShowstopper
Type: BugsPatches

Any news ? I have used this patch for more than one year now and it hasn't caused any issue whatsover ...

Do you know what could be done to integrate it in the trunk ? I don't like the idea of maintaining my own boost patches indefinitely ...

Note: See TracTickets for help on using tickets.