Skip to content

Commit a113e02

Browse files
bnoordhuisrvagg
authored andcommitted
deps: backport 3a9bfec from v8 upstream
Original commit message: 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} PR-URL: nodejs-private/node-private#44 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
1 parent 8138055 commit a113e02

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

deps/v8/src/zone.cc

+9-4
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ void* Zone::New(int size) {
8383
#else
8484
size;
8585
#endif
86-
87-
if (size_with_redzone > limit_ - position_) {
88-
result = NewExpand(size_with_redzone);
86+
const uintptr_t limit = reinterpret_cast<uintptr_t>(limit_);
87+
const uintptr_t position = reinterpret_cast<uintptr_t>(position_);
88+
// position_ > limit_ can be true after the alignment correction above.
89+
if (limit < position || size_with_redzone > limit - position) {
90+
result = NewExpand(size_with_redzone);
8991
} else {
9092
position_ += size_with_redzone;
9193
}
@@ -202,7 +204,10 @@ Address Zone::NewExpand(int size) {
202204
// Make sure the requested size is already properly aligned and that
203205
// there isn't enough room in the Zone to satisfy the request.
204206
DCHECK(size == RoundDown(size, kAlignment));
205-
DCHECK(size > limit_ - position_);
207+
DCHECK(limit_ < position_ ||
208+
reinterpret_cast<uintptr_t>(limit_) -
209+
reinterpret_cast<uintptr_t>(position_) <
210+
size);
206211

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

0 commit comments

Comments
 (0)