Opened 11 years ago

Closed 11 years ago

#6064 closed Bugs (invalid)

serialization fails with linked list of certain size

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

Description

Serialization of a custom-made simple linked list fails if the list is of a certain size. Seems linked to the depth of pointers comming from the root. In the provided code if the NUM_OF_NODES is set to:

  • 1200 everything works
  • 1300 deserialization fails with a segfault
  • 1500 serialization fails with a segfault

If the raw pointers are replaced with boost::shared_ptr the values of NUM_OF_NODES can be roughly cut in half to get the same effects. Changing the SerialTest classes size by adding additional fields has no effect. Compiled with gcc 4.5.2 from mingw on win xp

#include <iostream>
#include <fstream>
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

using namespace std;

class SerialTest
{
public:
	SerialTest* next;
	friend class boost::serialization::access;
	template<class Archive>
	void serialize(Archive & ar, const unsigned int version)
	{
		ar & next;
	}
	SerialTest()
	{
	}
};


int main()
{
	const size_t NUM_OF_NODES = 1200;
	SerialTest* root = new SerialTest;
	SerialTest* currentNode = root;
	for(size_t i = 0; i < NUM_OF_NODES; ++i)
	{
		SerialTest* newNode = new SerialTest;
		currentNode->next = newNode;
		currentNode = newNode;
	}

	{
		cout<<"opening ser file"<<endl;
		ofstream of("test.t");
		boost::archive::text_oarchive oa{of};
		cout<<"serialization"<<endl;
		oa << root;
	}

	{
		cout<<"opening deser file"<<endl;
		SerialTest* root2;
		ifstream ifs("test.t");
		cout<<"deserialization"<<endl;
		boost::archive::text_iarchive ia{ifs};
		ia >> root2;
	}
	cout<<"done"<<endl;

	return 0;
}

Change History (1)

comment:1 by Robert Ramey, 11 years ago

Resolution: invalid
Status: newclosed

This is a stack overflow due to recursion. It's not an issue with serialization library itself. It can happen with any recurrsive structure. If you wan't to do this, you'll have to either make the stack depth larger or alter your code to avoid such deep recurrsion.

Robert Ramey

Note: See TracTickets for help on using tickets.