Ignore:
Timestamp:
Jun 29, 2017, 5:58:18 PM (8 years ago)
Author:
[email protected]
Message:

Calculating postCapacity in unshiftCountSlowCase is wrong
https://bugs.webkit.org/show_bug.cgi?id=173992
<rdar://problem/32283199>

Reviewed by Keith Miller.

JSTests:

  • stress/unshiftCountSlowCase-correct-postCapacity.js: Added.

(temp):

Source/JavaScriptCore:

This patch fixes a bug inside unshiftCountSlowCase where we would use
more memory than we allocated. The bug was when deciding how much extra
space we have after the vector we've allocated. This area is called the
postCapacity. The largest legal postCapacity value we could use is the
space we allocated minus the space we need:
largestPossiblePostCapacity = newStorageCapacity - requiredVectorLength;
However, the code was calculating the postCapacity as:
postCapacity = max(newStorageCapacity - requiredVectorLength, count);

where count is how many elements we're appending. Depending on the inputs,
count could be larger than (newStorageCapacity - requiredVectorLength). This
would cause us to use more memory than we actually allocated.

  • runtime/JSArray.cpp:

(JSC::JSArray::unshiftCountSlowCase):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSArray.cpp

    r217869 r218977  
    378378    unsigned postCapacity = 0;
    379379    if (!addToFront)
    380         postCapacity = max(newStorageCapacity - requiredVectorLength, count);
     380        postCapacity = newStorageCapacity - requiredVectorLength;
    381381    else if (length < storage->vectorLength()) {
    382382        // Atomic decay, + the post-capacity cannot be greater than what is available.
     
    387387
    388388    unsigned newVectorLength = requiredVectorLength + postCapacity;
     389    RELEASE_ASSERT(newVectorLength <= MAX_STORAGE_VECTOR_LENGTH);
    389390    unsigned newIndexBias = newStorageCapacity - newVectorLength;
    390391
Note: See TracChangeset for help on using the changeset viewer.