[Boost-users] "invalid signature" in boost::archive::binary_iarchive

258 views
Skip to first unread message

Ibrahim Beicker

unread,
May 25, 2012, 2:44:07 PM5/25/12
to boost...@lists.boost.org
I had to port a multi-process application to 64 bits and I rely on boost serialization to send messages, that are maps of key-values, into Microsoft queues to the other modules. It works just fine into 32 bits but when I run it in 64 the constructor throws an "invalid signature" exception

void Message::fromBinary( const std::string& data )
{
  std::stringstream ss;
  ss << data;
  boost::archive::binary_iarchive ia(ss); //exception here

  ia >> *this;
}

I managed to debug into basic_binary_iarchive.ipp and this 'if' @ line 72 fails

if(file_signature != BOOST_ARCHIVE_SIGNATURE())
  boost::serialization::throw_exception(archive_exception(archive_exception::invalid_signature));

inside this file I have no debug symbols so I don't know the values of 'file_signature' and 'BOOST_ARCHIVE_SIGNATURE' or where BOOST_ARCHIVE_SIGNATURE is defined.

Some additional information: the modules are all running on the same machine, on windows 7 64-bits, and  compiled by visual studio 2010 x64 including static boost libraries 1.45.

What causes this and how can I fix it?

Robert Ramey

unread,
May 25, 2012, 6:02:33 PM5/25/12
to boost...@lists.boost.org
binary archives are not portable across architectures. Specifically
it is not possble to create a binary archive with 32 bit code and
and read that archive with 64 bit code. You'll have to write
your achive to some portable format such as a text archive.
Then you can load it on any platform.

Robert Ramey



_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Ibrahim Beicker

unread,
May 27, 2012, 9:17:09 PM5/27/12
to boost...@lists.boost.org
they are all running in the same 64 bits architecture. I've also tried the text archive but got the same error

2012/5/25 Robert Ramey <ra...@rrsd.com>

Jeff Flinn

unread,
May 28, 2012, 7:38:05 AM5/28/12
to boost...@lists.boost.org
On 5/25/2012 2:44 PM, Ibrahim Beicker wrote:
> I had to port a multi-process application to 64 bits and I rely on boost
> serialization to send messages, that are maps of key-values, into
> Microsoft queues to the other modules. It works just fine into 32 bits
> but when I run it in 64 the constructor throws an "invalid signature"
> exception
>
> void Message::fromBinary( const std::string& data )
> {
> std::stringstream ss;
> ss << data;
> boost::archive::binary_iarchive ia(ss); //exception here
>
> ia >> *this;
> }

Have you tried:

void Message::fromBinary( const std::string& data )
{
std::istringstream ss(data, std::ios::binary);

boost::archive::binary_iarchive ia(ss); //exception here

ia >> *this;
}

The output side should be opened with "binary" as well. I'm surprised
this didn't cause problems with 32bit as well.

Jeff

Ibrahim Beicker

unread,
May 28, 2012, 9:58:57 AM5/28/12
to boost...@lists.boost.org
thanks for your help, but I ended up discovering that the message was unaligned 4 bytes to the right, with x00 x00 x00 x00 x22 when the message should start with x22, hence the invalid signature.

The problem was with the constructor of boost::asio::buffer, it was boost::asio::buffer(&m_messageSize, sizeof(unsigned int)) when it should be
boost::asio::buffer(&m_messageSize, sizeof(std::size_t))
since in 64 bits sizeof(unsigned int) = 4 and sizeof(size_t) is 8

problem solved

2012/5/28 Jeff Flinn <Jeffre...@gmail.com>
Reply all
Reply to author
Forward
0 new messages