Skip to content

Commit 3a9bfec

Browse files
jakobkummerowCommit bot
authored andcommitted
Fix overflow issue in Zone::New
When requesting a large allocation near the end of the address space, the computation could overflow and erroneously *not* grow the Zone as required. BUG=chromium:606115 LOG=y Review-Url: https://codereview.chromium.org/1930873002 Cr-Commit-Position: refs/heads/master@{#35903}
1 parent 25fbb90 commit 3a9bfec

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/zone.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ void* Zone::New(size_t size) {
104104
Address result = position_;
105105

106106
const size_t size_with_redzone = size + kASanRedzoneBytes;
107-
if (limit_ < position_ + size_with_redzone) {
107+
const uintptr_t limit = reinterpret_cast<uintptr_t>(limit_);
108+
const uintptr_t position = reinterpret_cast<uintptr_t>(position_);
109+
// position_ > limit_ can be true after the alignment correction above.
110+
if (limit < position || size_with_redzone > limit - position) {
108111
result = NewExpand(size_with_redzone);
109112
} else {
110113
position_ += size_with_redzone;
@@ -221,7 +224,10 @@ Address Zone::NewExpand(size_t size) {
221224
// Make sure the requested size is already properly aligned and that
222225
// there isn't enough room in the Zone to satisfy the request.
223226
DCHECK_EQ(size, RoundDown(size, kAlignment));
224-
DCHECK_LT(limit_, position_ + size);
227+
DCHECK(limit_ < position_ ||
228+
reinterpret_cast<uintptr_t>(limit_) -
229+
reinterpret_cast<uintptr_t>(position_) <
230+
size);
225231

226232
// Compute the new segment size. We use a 'high water mark'
227233
// strategy, where we increase the segment size every time we expand

0 commit comments

Comments
 (0)