Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#11360 closed Bugs (fixed)

Undefined behavior in extended_type_info_typeid default constructor?

Reported by: Martin Schulze <spam.martin.schulze@…> Owned by: Robert Ramey
Milestone: To Be Determined Component: serialization
Version: Boost 1.58.0 Severity: Problem
Keywords: Cc:

Description

Using the undefined behavior sanitizer I probably hit the same problem as #11204

However, I also got another message:

/usr/include/boost/serialization/extended_type_info_typeid.hpp:87:59: runtime error: member call on address 0x0000010adb60 which does not point to an object of type 'extended_type_info_typeid'
0x0000010adb60: note: object has invalid vptr
 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              invalid vptr

Maybe this message triggers the following messages (as described in #11204)

Anyways, in extended_type_info_typeid.hpp I found

extended_type_info_typeid() :
        typeid_system::extended_type_info_typeid_0(get_key()) // <--- line 87
{
   // ...
}
  // ...
const char * get_key() const { // <--- line 108
    return boost::serialization::guid< T >();
}

As we can see, the member function get_key is called to initialize a base class.

According to § 12.6.2.13 of the standard (I am using n3242) calling a member function in a ctor-initializer before all base classes have been initialized is undefined behavior.

Change History (3)

comment:1 by Robert Ramey, 7 years ago

Made a change to fix this. It's been uploaded to the develop branch. So I'm going to mark this as fixed

comment:2 by Robert Ramey, 7 years ago

Resolution: fixed
Status: newclosed

comment:3 by anonymous, 7 years ago

For posterity's sake:

https://github.com/boostorg/serialization/commit/4f83fc163afad8fc078afcb0eccfbda1f161b3b6

-        typeid_system::extended_type_info_typeid_0(get_key())
+        typeid_system::extended_type_info_typeid_0(
+            boost::serialization::guid< T >()
+        )

Just hit this myself and wanted to apply a patch locally.

Note: See TracTickets for help on using tickets.