Changeset 216076 in webkit


Ignore:
Timestamp:
May 2, 2017, 10:55:11 AM (8 years ago)
Author:
mark.lam@apple.com
Message:

JSFixedArray::allocationSize() should not allow for allocation failure.
https://bugs.webkit.org/show_bug.cgi?id=171516

Reviewed by Geoffrey Garen.

Since JSFixedArray::createFromArray() now handles allocation failures by throwing
OutOfMemoryErrors, its helper function allocationSize() (which computes the buffer
size to allocate) should also allow for allocation failure on overflow.

This issue is covered by the stress/js-fixed-array-out-of-memory.js test when
run on 32-bit builds.

  • runtime/JSFixedArray.h:

(JSC::JSFixedArray::tryCreate):
(JSC::JSFixedArray::allocationSize):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r216058 r216076  
     12017-05-02  Mark Lam  <mark.lam@apple.com>
     2
     3        JSFixedArray::allocationSize() should not allow for allocation failure.
     4        https://bugs.webkit.org/show_bug.cgi?id=171516
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Since JSFixedArray::createFromArray() now handles allocation failures by throwing
     9        OutOfMemoryErrors, its helper function allocationSize() (which computes the buffer
     10        size to allocate) should also allow for allocation failure on overflow.
     11
     12        This issue is covered by the stress/js-fixed-array-out-of-memory.js test when
     13        run on 32-bit builds.
     14
     15        * runtime/JSFixedArray.h:
     16        (JSC::JSFixedArray::tryCreate):
     17        (JSC::JSFixedArray::allocationSize):
     18
    1192017-05-01  Zan Dobersek  <zdobersek@igalia.com>
    220
  • trunk/Source/JavaScriptCore/runtime/JSFixedArray.h

    r215919 r216076  
    123123    ALWAYS_INLINE static JSFixedArray* tryCreate(VM& vm, Structure* structure, unsigned size)
    124124    {
    125         void* buffer = tryAllocateCell<JSFixedArray>(vm.heap, allocationSize(size));
     125        Checked<size_t, RecordOverflow> checkedAllocationSize = allocationSize(size);
     126        if (UNLIKELY(checkedAllocationSize.hasOverflowed()))
     127            return nullptr;
     128
     129        void* buffer = tryAllocateCell<JSFixedArray>(vm.heap, checkedAllocationSize.unsafeGet());
    126130        if (UNLIKELY(!buffer))
    127131            return nullptr;
     
    141145
    142146
    143     static size_t allocationSize(Checked<size_t> numItems)
     147    static Checked<size_t, RecordOverflow> allocationSize(Checked<size_t, RecordOverflow> numItems)
    144148    {
    145         return (offsetOfData() + numItems * sizeof(WriteBarrier<Unknown>)).unsafeGet();
     149        return offsetOfData() + numItems * sizeof(WriteBarrier<Unknown>);
    146150    }
    147151};
Note: See TracChangeset for help on using the changeset viewer.