Modify

Ticket #3365 (closed Bugs: fixed)

Opened 5 years ago

Last modified 2 years ago

Serialization of multi_index_container is non portable.

Reported by: Ilia V. Sochenkov <ivsochenkov@…> Owned by: joaquin
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

Change History

comment:1 Changed 5 years ago by joaquin

  • Status changed from new to closed
  • Resolution set to fixed

(In [55994]) fixed #3365

comment:2 Changed 5 years ago by joaquin

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 2 years ago by Hajo Kirchhoff <mailinglists@…>

  • Cc mailinglists@… added
  • Status changed from closed to reopened
  • Resolution fixed deleted
  • Severity changed from Cosmetic to Problem

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 2 years ago by joaquin

Hi Hajo,

Please check whether

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

solves the issue. Thank you!

comment:5 Changed 2 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 2 years ago by joaquin

  • Status changed from reopened to closed
  • Resolution set to fixed
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.