In Boost.Pool, be careful not to overflow allocated chunk size.
- Resolves: #828857
This commit is contained in:
parent
f4262d6502
commit
eaa3d38783
110
boost-1.47.0-pool.patch
Normal file
110
boost-1.47.0-pool.patch
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
diff -up boost_1_47_0/boost/pool/pool.hpp\~ boost_1_47_0/boost/pool/pool.hpp
|
||||||
|
--- boost_1_47_0/boost/pool/pool.hpp~ 2011-01-11 15:22:32.000000000 +0100
|
||||||
|
+++ boost_1_47_0/boost/pool/pool.hpp 2012-06-07 01:00:26.936184589 +0200
|
||||||
|
@@ -26,6 +26,10 @@
|
||||||
|
|
||||||
|
#include <boost/pool/poolfwd.hpp>
|
||||||
|
|
||||||
|
+// std::numeric_limits
|
||||||
|
+#include <boost/limits.hpp>
|
||||||
|
+// boost::math::static_lcm
|
||||||
|
+#include <boost/math/common_factor.hpp>
|
||||||
|
// boost::details::pool::ct_lcm
|
||||||
|
#include <boost/pool/detail/ct_gcd_lcm.hpp>
|
||||||
|
// boost::details::pool::lcm
|
||||||
|
@@ -187,6 +191,15 @@ class pool: protected simple_segregated_
|
||||||
|
return details::pool::lcm<size_type>(requested_size, min_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
+ size_type max_chunks() const
|
||||||
|
+ { //! Calculated maximum number of memory chunks that can be allocated in a single call by this Pool.
|
||||||
|
+ size_type partition_size = alloc_size();
|
||||||
|
+ size_type POD_size = math::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type);
|
||||||
|
+ size_type max_chunks = (std::numeric_limits<size_type>::max() - POD_size) / alloc_size();
|
||||||
|
+
|
||||||
|
+ return max_chunks;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
// for the sake of code readability :)
|
||||||
|
static void * & nextof(void * const ptr)
|
||||||
|
{ return *(static_cast<void **>(ptr)); }
|
||||||
|
@@ -198,7 +211,10 @@ class pool: protected simple_segregated_
|
||||||
|
const size_type nnext_size = 32,
|
||||||
|
const size_type nmax_size = 0)
|
||||||
|
:list(0, 0), requested_size(nrequested_size), next_size(nnext_size), start_size(nnext_size),max_size(nmax_size)
|
||||||
|
- { }
|
||||||
|
+ {
|
||||||
|
+ set_next_size(nnext_size);
|
||||||
|
+ set_max_size(nmax_size);
|
||||||
|
+ }
|
||||||
|
|
||||||
|
~pool() { purge_memory(); }
|
||||||
|
|
||||||
|
@@ -213,9 +229,17 @@ class pool: protected simple_segregated_
|
||||||
|
|
||||||
|
// These functions are extensions!
|
||||||
|
size_type get_next_size() const { return next_size; }
|
||||||
|
- void set_next_size(const size_type nnext_size) { next_size = start_size = nnext_size; }
|
||||||
|
+ void set_next_size(const size_type nnext_size)
|
||||||
|
+ {
|
||||||
|
+ BOOST_USING_STD_MIN();
|
||||||
|
+ next_size = start_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(nnext_size, max_chunks());
|
||||||
|
+ }
|
||||||
|
size_type get_max_size() const { return max_size; }
|
||||||
|
- void set_max_size(const size_type nmax_size) { max_size = nmax_size; }
|
||||||
|
+ void set_max_size(const size_type nmax_size)
|
||||||
|
+ {
|
||||||
|
+ BOOST_USING_STD_MIN();
|
||||||
|
+ max_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(nmax_size, max_chunks());
|
||||||
|
+ }
|
||||||
|
size_type get_requested_size() const { return requested_size; }
|
||||||
|
|
||||||
|
// Both malloc and ordered_malloc do a quick inlined check first for any
|
||||||
|
@@ -447,9 +471,9 @@ void * pool<UserAllocator>::malloc_need_
|
||||||
|
|
||||||
|
BOOST_USING_STD_MIN();
|
||||||
|
if(!max_size)
|
||||||
|
- next_size <<= 1;
|
||||||
|
+ set_next_size(next_size << 1);
|
||||||
|
else if( next_size*partition_size/requested_size < max_size)
|
||||||
|
- next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
|
||||||
|
+ set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
|
||||||
|
|
||||||
|
// initialize it,
|
||||||
|
store().add_block(node.begin(), node.element_size(), partition_size);
|
||||||
|
@@ -476,9 +500,9 @@ void * pool<UserAllocator>::ordered_mall
|
||||||
|
|
||||||
|
BOOST_USING_STD_MIN();
|
||||||
|
if(!max_size)
|
||||||
|
- next_size <<= 1;
|
||||||
|
+ set_next_size(next_size << 1);
|
||||||
|
else if( next_size*partition_size/requested_size < max_size)
|
||||||
|
- next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
|
||||||
|
+ set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
|
||||||
|
|
||||||
|
// initialize it,
|
||||||
|
// (we can use "add_block" here because we know that
|
||||||
|
@@ -519,6 +543,9 @@ void * pool<UserAllocator>::ordered_mall
|
||||||
|
template <typename UserAllocator>
|
||||||
|
void * pool<UserAllocator>::ordered_malloc(const size_type n)
|
||||||
|
{
|
||||||
|
+ if (n > max_chunks())
|
||||||
|
+ return 0;
|
||||||
|
+
|
||||||
|
const size_type partition_size = alloc_size();
|
||||||
|
const size_type total_req_size = n * requested_size;
|
||||||
|
const size_type num_chunks = total_req_size / partition_size +
|
||||||
|
@@ -549,9 +576,9 @@ void * pool<UserAllocator>::ordered_mall
|
||||||
|
|
||||||
|
BOOST_USING_STD_MIN();
|
||||||
|
if(!max_size)
|
||||||
|
- next_size <<= 1;
|
||||||
|
+ set_next_size(next_size << 1);
|
||||||
|
else if( next_size*partition_size/requested_size < max_size)
|
||||||
|
- next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
|
||||||
|
+ set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
|
||||||
|
|
||||||
|
// insert it into the list,
|
||||||
|
// handle border case
|
||||||
|
|
||||||
|
Diff finished. Thu Jun 7 01:00:38 2012
|
11
boost.spec
11
boost.spec
@ -28,7 +28,7 @@ Name: boost
|
|||||||
Summary: The free peer-reviewed portable C++ source libraries
|
Summary: The free peer-reviewed portable C++ source libraries
|
||||||
Version: 1.46.0
|
Version: 1.46.0
|
||||||
%define version_enc 1_46_0
|
%define version_enc 1_46_0
|
||||||
Release: 3%{?dist}
|
Release: 4%{?dist}
|
||||||
License: Boost
|
License: Boost
|
||||||
|
|
||||||
# The CMake build framework (set of CMakeLists.txt and module.cmake files) is
|
# The CMake build framework (set of CMakeLists.txt and module.cmake files) is
|
||||||
@ -110,6 +110,10 @@ Patch5: boost-1.46.0-spirit.patch
|
|||||||
# https://svn.boost.org/trac/boost/changeset/69684)
|
# https://svn.boost.org/trac/boost/changeset/69684)
|
||||||
Patch6: boost-1.46.0-ptree-assertion.patch
|
Patch6: boost-1.46.0-ptree-assertion.patch
|
||||||
|
|
||||||
|
# https://bugzilla.redhat.com/show_bug.cgi?id=828856
|
||||||
|
# https://bugzilla.redhat.com/show_bug.cgi?id=828857
|
||||||
|
Patch7: boost-1.47.0-pool.patch
|
||||||
|
|
||||||
%bcond_with tests
|
%bcond_with tests
|
||||||
%bcond_with docs_generated
|
%bcond_with docs_generated
|
||||||
|
|
||||||
@ -438,6 +442,7 @@ sed 's/_FEDORA_SONAME/%{sonamever}/' %{PATCH2} | %{__patch} -p0 --fuzz=0
|
|||||||
%patch4 -p2
|
%patch4 -p2
|
||||||
%patch5 -p0
|
%patch5 -p0
|
||||||
%patch6 -p1
|
%patch6 -p1
|
||||||
|
%patch7 -p1
|
||||||
|
|
||||||
# Fix some permissions
|
# Fix some permissions
|
||||||
find ./boost/range -type f -name '*.hpp' -exec chmod 644 {} \;
|
find ./boost/range -type f -name '*.hpp' -exec chmod 644 {} \;
|
||||||
@ -853,6 +858,10 @@ find $RPM_BUILD_ROOT%{_includedir}/ \( -name '*.pl' -o -name '*.sh' \) -exec %{_
|
|||||||
%{_bindir}/bjam
|
%{_bindir}/bjam
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Wed Jun 6 2012 Petr Machata <pmachata@redhat.com> - 1.46.0-4
|
||||||
|
- In Boost.Pool, be careful not to overflow allocated chunk size.
|
||||||
|
- Resolves: #828857
|
||||||
|
|
||||||
* Thu Jun 23 2011 Denis Arnaud <denis.arnaud_fedora@m4x.org> - 1.46.0-3
|
* Thu Jun 23 2011 Denis Arnaud <denis.arnaud_fedora@m4x.org> - 1.46.0-3
|
||||||
- Fixed compilation errors when compiling JSON-related Boost::Property_Tree
|
- Fixed compilation errors when compiling JSON-related Boost::Property_Tree
|
||||||
- Related: #715611
|
- Related: #715611
|
||||||
|
Loading…
Reference in New Issue
Block a user