Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: third_party/tcmalloc/chromium/src/common.cc

Issue 11857007: TCMalloc: restrict maximum size of memory ranges (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Drive-by patch of int to size_t. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/tcmalloc/chromium/src/common.cc
diff --git a/third_party/tcmalloc/chromium/src/common.cc b/third_party/tcmalloc/chromium/src/common.cc
index 5a55b3908391666703e11c00afc45536f92a4faf..7fbae844efd23083bdbb74f209e20ca30f7f90a2 100644
--- a/third_party/tcmalloc/chromium/src/common.cc
+++ b/third_party/tcmalloc/chromium/src/common.cc
@@ -38,8 +38,20 @@
#include <unistd.h> // for getpagesize
#endif
+#include <limits>
+
namespace tcmalloc {
+bool IsAllocSizePermitted(size_t alloc_size) {
+ // Never allow an allocation of a contiguous area larger than what can
+ // be indexed via an int. This is meant as a security mitigation, see
+ // crbug.com/169369 for more background.
+
+ // Remove kPageSize to account for various rounding, padding and to
+ // have a small margin.
+ return alloc_size <= ((std::numeric_limits<int>::max)() - kPageSize);
+}
+
// Note: the following only works for "n"s that fit in 32-bits, but
// that is fine since we only use it for small sizes.
static inline int LgFloor(size_t n) {

Powered by Google App Engine
This is Rietveld 408576698