Modify

Opened 8 years ago

Closed 6 years ago

#3365 closed Bugs (fixed)

Serialization of multi_index_container is non portable.

Reported by: Ilia V. Sochenkov <ivsochenkov@…> Owned by: Joaquín M López Muñoz
Milestone: Boost 1.40.0 Component: multi_index
Version: Boost 1.38.0 Severity: Problem
Keywords: multi_index_container serialization, multi_index Cc: mailinglists@…

Description

multi_index_container save and load member-functions use type "std::size_t" to serialize a container's size instead of boost::serialization::collection_size_type. It may cause some problems when portable binary archives are used, because std::size_t has different size in different platforms. boost::serialization::collection_size_type can be treated specially by portable archive implementations: collection_size_type used in the serialization implementation for the standart containers.

Attachments (0)

Change History (6)

comment:1 Changed 8 years ago by Joaquín M López Muñoz

Resolution: fixed
Status: newclosed

(In [55994]) fixed #3365

comment:2 Changed 8 years ago by Joaquín M López Muñoz

Ilia, just fixed the problem in changeset

https://svn.boost.org/trac/boost/changeset/55994

I'd appreciate if you could check everything's OK on your side.

comment:3 Changed 6 years ago by Hajo Kirchhoff <mailinglists@…>

Cc: mailinglists@… added
Resolution: fixed
Severity: CosmeticProblem
Status: closedreopened

The changeset may fix this problem (haven't checked), but line 667 (of this changeset) might cause data truncation under x64 bit and a compiler warning.

    serialization::collection_size_type       s;
    detail::serialization_version<value_type> value_version;
    if(version<1){
      std::size_t sz;
      ar>>serialization::make_nvp("count",sz);
      s=sz;  /***** Error here *****/
    }

With x64 bit compilation (Visual Studio 2008, boost 1.44) collection_size_type is unsigned int (32 Bit), whereas size_t is an unsigned long (64 Bit). The assignment s=sz gets truncated and issues a warning

boost\boost/multi_index_container.hpp(673) : error C4267: 'argument' : conversion from 'size_t' to 'const unsigned int', possible loss of data

Since our project treats this warning as an error, the code does not compile.

The patch here is straightforward: simply cast the result. There is nothing we can do in this case anyway and also it is pretty unlikely that any user in the world will serialise more than 232 items.

@@ -670,7 +670,7 @@
     if(version<1){
       std::size_t sz;
       ar>>serialization::make_nvp("count",sz);
-      s=sz;
+      s=(serialization::collection_size_type)sz;
     }
     else{
       ar>>serialization::make_nvp("count",s);

comment:4 Changed 6 years ago by Joaquín M López Muñoz

Hi Hajo,

Please check whether

https://svn.boost.org/trac/boost/changeset/75643

solves the issue. Thank you!

comment:5 Changed 6 years ago by Hajo Kirchhoff <mailinglists@…>

Hi Joaquin, yes, that should solve the issue. Thanks. And thanks for your work :-) (fixed in 1.49) You can close this ticket again...

comment:6 Changed 6 years ago by Joaquín M López Muñoz

Resolution: fixed
Status: reopenedclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Joaquín M López Muñoz.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.