boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
96 stars 116 forks source link

pmr::monotonic_buffer_resource crashes on large single allocations #159

Closed jmlundberg closed 3 years ago

jmlundberg commented 3 years ago
boost::container::pmr::monotonic_buffer_resource mr (boost::container::pmr::get_default_resource());
boost::container::pmr::vector<char> vchar2(&r);
const auto zz = 5368709127;
std::cout << zz <<std::endl;
vchar.resize(zz);

crashes at memset. windows, msvc, 64 bit.

vinniefalco commented 3 years ago

The function increase_next_buffer_at_least_to here: https://github.com/boostorg/container/blob/5a52472cd00994bf1752e92c1c178a5a822a36cb/src/monotonic_buffer_resource.cpp#L148

Does not make the next buffer large enough to hold bytes, because the math function floor_log2 it relies on is 32-bit and not 64-bit: https://github.com/boostorg/intrusive/blob/d8761780b0386c53ab144173a5fdc536ee2e1da8/include/boost/intrusive/detail/math.hpp#L79

   inline std::size_t floor_log2 (std::size_t x)
   {
      unsigned long log2;
      BOOST_INTRUSIVE_BSR_INTRINSIC( &log2, (unsigned long)x );
      return log2;
   }
igaztanaga commented 3 years ago

Many thanks for the report. As Vinnie has correctly identified, it's a Boost.Intrusive problem, just fixed in boostorg/intrusive#52.