Subject: [Boost-bugs] [Boost C++ Libraries] #13563: Error deserializing empty forward_list
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2018-05-11 12:03:11
#13563: Error deserializing empty forward_list
----------------------------------------+---------------------------
Reporter: Maximiliano Pin <mxcpin@â¦> | Owner: Robert Ramey
Type: Patches | Status: new
Milestone: To Be Determined | Component: serialization
Version: Boost 1.67.0 | Severity: Showstopper
Keywords: |
----------------------------------------+---------------------------
Deserializing an empty forward_list is broken if the elements aren't
default constructible (with old compilers it's enough that elements have a
non-trivial default constructor).
A patch is attached. The problem is that the first element is always
loaded first, even if the list is empty. The result may be a crash or any
undefined behavior, since deserialization goes out of sync.
Test case:
{{{
#include <boost/serialization/forward_list.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <forward_list>
#include <iostream>
#include <sstream>
struct Foo
{
int x;
Foo(int a) : x(a) {};
template<class Archive>
void serialize(Archive& ar, const unsigned int) { ar & x; }
private:
friend class boost::serialization::access;
Foo() = default;
};
int main()
{
std::forward_list<Foo> flist;
std::ostringstream oss;
boost::archive::binary_oarchive oa{oss};
oa << flist;
std::istringstream iss{oss.str()};
boost::archive::binary_iarchive ia{iss};
ia >> flist;
}
}}}
Results in:
{{{
terminate called after throwing an instance of
'boost::archive::archive_exception'
what(): input stream error
Aborted (core dumped)
}}}
-- Ticket URL: <https://svn.boost.org/trac10/ticket/13563> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2018-05-11 12:09:26 UTC