[Boost-bugs] [Boost C++ Libraries] #13092: Serializing pointer makes sanitizer complain about "reference binding to misaligned address"

Subject: [Boost-bugs] [Boost C++ Libraries] #13092: Serializing pointer makes sanitizer complain about "reference binding to misaligned address"
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-06-23 08:48:25


#13092: Serializing pointer makes sanitizer complain about "reference binding to
misaligned address"
------------------------------+---------------------------
 Reporter: fiesh@… | Owner: ramey
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: serialization
  Version: Boost 1.63.0 | Severity: Problem
 Keywords: |
------------------------------+---------------------------
 Consider the following program:

 {{{
 #include <memory>
 #include <sstream>

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

 struct S
 {
         int i;
         char c;

         template <class Archive>
         void serialize(Archive & ar, const unsigned int version)
         {
                 ar & i;
                 ar & c;
         }
 };

 int main()
 {
         const auto s0 = std::make_shared<S>();
         s0->i = 42;
         s0->c = 'c';

         std::stringstream ss;

         {
                 boost::archive::text_oarchive oa(ss);
                 oa << s0;
         }

         std::shared_ptr<S> s1;
         {
                 boost::archive::text_iarchive ia(ss);
                 ia >> s1;
         }

         return 0;
 }
 }}}

 What is important is that we use a pointer to the struct.

 I then get the following output, which seems to be a real issue probably
 mitigated by x86's lax requirements on alignment:

 {{{
 % g++ -lboost_serialization -fsanitize=address -fsanitize=leak
 -fsanitize=undefined -fsanitize=shift -fsanitize=integer-divide-by-zero
 -fsanitize=unreachable -fsanitize=vla-bound -fsanitize=null
 -fsanitize=return -fsanitize=signed-integer-overflow -fsanitize=bounds
 -fsanitize=alignment -fsanitize=object-size -fsanitize=float-divide-by-
 zero -fsanitize=float-cast-overflow -fsanitize=nonnull-attribute
 -fsanitize=returns-nonnull-attribute -fsanitize=bool -fsanitize=enum -fno-
 sanitize=vptr t.cpp&& LD_PRELOAD=/usr/lib/gcc/x86_64-pc-linux-
 gnu/6.3.0/libasan.so ./a.out
 % LD_PRELOAD=/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/libasan.so ./a.out
 /usr/include/boost/archive/detail/iserializer.hpp:540:19: runtime error:
 reference binding to misaligned address 0x000000000002 for type 'struct
 S', which requires 4 byte alignment
 0x000000000002: note: pointer points here
 <memory cannot be printed>
 /usr/include/boost/archive/detail/iserializer.hpp:541:67: runtime error:
 reference binding to misaligned address 0x000000000002 for type 'const
 struct S', which requires 4 byte alignment
 0x000000000002: note: pointer points here
 <memory cannot be printed>
 % LD_PRELOAD=/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/libasan.so ./a.out
 % LD_PRELOAD=/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/libasan.so ./a.out
 /usr/include/boost/archive/detail/iserializer.hpp:540:19: runtime error:
 reference binding to misaligned address 0x000000000002 for type 'struct
 S', which requires 4 byte alignment
 0x000000000002: note: pointer points here
 <memory cannot be printed>
 /usr/include/boost/archive/detail/iserializer.hpp:541:67: runtime error:
 reference binding to misaligned address 0x000000000002 for type 'const
 struct S', which requires 4 byte alignment
 0x000000000002: note: pointer points here
 <memory cannot be printed>
 }}}

 Note how it only occurs sometimes, probably depending on what memory
 address happened to have been returned.

--
Ticket URL: <https://svn.boost.org/trac10/boost/ticket/13092>
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 : 2017-06-23 08:51:46 UTC