Diff
Modified: branches/safari-603-branch/Source/_javascript_Core/ChangeLog (211101 => 211102)
--- branches/safari-603-branch/Source/_javascript_Core/ChangeLog 2017-01-24 21:22:39 UTC (rev 211101)
+++ branches/safari-603-branch/Source/_javascript_Core/ChangeLog 2017-01-24 21:22:42 UTC (rev 211102)
@@ -1,5 +1,43 @@
2017-01-24 Matthew Hanson <matthew_han...@apple.com>
+ Merge r211043. rdar://problem/30134434
+
+ 2017-01-23 Michael Saboff <msab...@apple.com>
+
+ IntlObject uses JSArray::tryCreateUninitialized in an unsafe way
+ https://bugs.webkit.org/show_bug.cgi?id=167288
+
+ Reviewed by Filip Pizlo.
+
+ Refactored the following "create" methods into a "tryCreate" method and a
+ "create" wrapper: JSArray::create(), Butterfly::create() and
+ createArrayButterfly().
+
+ Changed IntlObject.cpp to use JSArray::tryCreate() as it is simpler to use
+ by not requiring the caller to be GC savey. The performance benefits of
+ tryCreateUninitialized() are not needed by the IntlObject c++ code.
+
+ Did not add a new test as the bug caused LayoutTests/js/intl.html to fail
+ reliably with the JSC option values scribbleFreeCells=true,
+ collectContinuously=true and JSC_useGenerationalGC=false.
+
+ * runtime/Butterfly.h:
+ * runtime/ButterflyInlines.h:
+ (JSC::Butterfly::tryCreate): Added.
+ (JSC::Butterfly::create):
+ * runtime/IntlObject.cpp:
+ (JSC::canonicalizeLocaleList):
+ (JSC::lookupSupportedLocales):
+ (JSC::intlObjectFuncGetCanonicalLocales):
+ * runtime/JSArray.h:
+ (JSC::createContiguousArrayButterfly): Deleted.
+ (JSC::tryCreateArrayButterfly): Added.
+ (JSC::createArrayButterfly):
+ (JSC::JSArray::tryCreate): Added.
+ (JSC::JSArray::create):
+
+2017-01-24 Matthew Hanson <matthew_han...@apple.com>
+
Merge r210971. rdar://problem/30115838
2017-01-20 Saam Barati <sbar...@apple.com>
Modified: branches/safari-603-branch/Source/_javascript_Core/runtime/Butterfly.h (211101 => 211102)
--- branches/safari-603-branch/Source/_javascript_Core/runtime/Butterfly.h 2017-01-24 21:22:39 UTC (rev 211101)
+++ branches/safari-603-branch/Source/_javascript_Core/runtime/Butterfly.h 2017-01-24 21:22:42 UTC (rev 211102)
@@ -111,6 +111,7 @@
static Butterfly* createUninitialized(VM&, JSCell* intendedOwner, size_t preCapacity, size_t propertyCapacity, bool hasIndexingHeader, size_t indexingPayloadSizeInBytes);
+ static Butterfly* tryCreate(VM& vm, JSCell*, size_t preCapacity, size_t propertyCapacity, bool hasIndexingHeader, const IndexingHeader& indexingHeader, size_t indexingPayloadSizeInBytes);
static Butterfly* create(VM&, JSCell* intendedOwner, size_t preCapacity, size_t propertyCapacity, bool hasIndexingHeader, const IndexingHeader&, size_t indexingPayloadSizeInBytes);
static Butterfly* create(VM&, JSCell* intendedOwner, Structure*);
Modified: branches/safari-603-branch/Source/_javascript_Core/runtime/ButterflyInlines.h (211101 => 211102)
--- branches/safari-603-branch/Source/_javascript_Core/runtime/ButterflyInlines.h 2017-01-24 21:22:39 UTC (rev 211101)
+++ branches/safari-603-branch/Source/_javascript_Core/runtime/ButterflyInlines.h 2017-01-24 21:22:42 UTC (rev 211102)
@@ -67,11 +67,13 @@
return result;
}
-inline Butterfly* Butterfly::create(VM& vm, JSCell* intendedOwner, size_t preCapacity, size_t propertyCapacity, bool hasIndexingHeader, const IndexingHeader& indexingHeader, size_t indexingPayloadSizeInBytes)
+inline Butterfly* Butterfly::tryCreate(VM& vm, JSCell*, size_t preCapacity, size_t propertyCapacity, bool hasIndexingHeader, const IndexingHeader& indexingHeader, size_t indexingPayloadSizeInBytes)
{
- Butterfly* result = createUninitialized(
- vm, intendedOwner, preCapacity, propertyCapacity, hasIndexingHeader,
- indexingPayloadSizeInBytes);
+ size_t size = totalSize(preCapacity, propertyCapacity, hasIndexingHeader, indexingPayloadSizeInBytes);
+ void* base = vm.auxiliarySpace.tryAllocate(size);
+ if (!base)
+ return nullptr;
+ Butterfly* result = fromBase(base, preCapacity, propertyCapacity);
if (hasIndexingHeader)
*result->indexingHeader() = indexingHeader;
memset(result->propertyStorage() - propertyCapacity, 0, propertyCapacity * sizeof(EncodedJSValue));
@@ -78,6 +80,14 @@
return result;
}
+inline Butterfly* Butterfly::create(VM& vm, JSCell* intendedOwner, size_t preCapacity, size_t propertyCapacity, bool hasIndexingHeader, const IndexingHeader& indexingHeader, size_t indexingPayloadSizeInBytes)
+{
+ Butterfly* result = tryCreate(vm, intendedOwner, preCapacity, propertyCapacity, hasIndexingHeader, indexingHeader, indexingPayloadSizeInBytes);
+
+ RELEASE_ASSERT(result);
+ return result;
+}
+
inline Butterfly* Butterfly::create(VM& vm, JSCell* intendedOwner, Structure* structure)
{
return create(
Modified: branches/safari-603-branch/Source/_javascript_Core/runtime/IntlObject.cpp (211101 => 211102)
--- branches/safari-603-branch/Source/_javascript_Core/runtime/IntlObject.cpp 2017-01-24 21:22:39 UTC (rev 211101)
+++ branches/safari-603-branch/Source/_javascript_Core/runtime/IntlObject.cpp 2017-01-24 21:22:42 UTC (rev 211102)
@@ -548,7 +548,12 @@
JSObject* localesObject;
if (locales.isString()) {
// a. Let aLocales be CreateArrayFromList(«locales»).
- JSArray* localesArray = JSArray::tryCreateUninitialized(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous), 1);
+ JSArray* localesArray = JSArray::tryCreate(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous), 1);
+ if (!localesArray) {
+ throwOutOfMemoryError(&state, scope);
+ RETURN_IF_EXCEPTION(scope, Vector<String>());
+ }
+
localesArray->initializeIndex(vm, 0, locales);
// 4. Let O be ToObject(aLocales).
localesObject = localesArray;
@@ -887,7 +892,7 @@
// 3. Let subset be an empty List.
JSGlobalObject* globalObject = state.jsCallee()->globalObject();
- JSArray* subset = JSArray::tryCreateUninitialized(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithUndecided), 0);
+ JSArray* subset = JSArray::tryCreate(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithUndecided), 0);
if (!subset) {
throwOutOfMemoryError(&state, scope);
return nullptr;
@@ -1031,7 +1036,7 @@
// 2. Return CreateArrayFromList(ll).
JSGlobalObject* globalObject = state->jsCallee()->globalObject();
- JSArray* localeArray = JSArray::tryCreateUninitialized(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous), localeList.size());
+ JSArray* localeArray = JSArray::tryCreate(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous), localeList.size());
if (!localeArray) {
throwOutOfMemoryError(state, scope);
return encodedJSValue();
Modified: branches/safari-603-branch/Source/_javascript_Core/runtime/JSArray.h (211101 => 211102)
--- branches/safari-603-branch/Source/_javascript_Core/runtime/JSArray.h 2017-01-24 21:22:39 UTC (rev 211101)
+++ branches/safari-603-branch/Source/_javascript_Core/runtime/JSArray.h 2017-01-24 21:22:42 UTC (rev 211102)
@@ -52,13 +52,18 @@
}
public:
+ static JSArray* tryCreate(VM&, Structure*, unsigned initialLength = 0);
static JSArray* create(VM&, Structure*, unsigned initialLength = 0);
static JSArray* createWithButterfly(VM&, GCDeferralContext*, Structure*, Butterfly*);
// tryCreateUninitialized is used for fast construction of arrays whose size and
- // contents are known at time of creation. Clients of this interface must:
+ // contents are known at time of creation. This should be considered a private API.
+ // Clients of this interface must:
// - null-check the result (indicating out of memory, or otherwise unable to allocate vector).
// - call 'initializeIndex' for all properties in sequence, for 0 <= i < initialLength.
+ // - Provide a valid GCDefferalContext* if they might garbage collect when initializing properties,
+ // otherwise the caller can provide a null GCDefferalContext*.
+ //
JS_EXPORT_PRIVATE static JSArray* tryCreateUninitialized(VM&, GCDeferralContext*, Structure*, unsigned initialLength);
static JSArray* tryCreateUninitialized(VM& vm, Structure* structure, unsigned initialLength)
{
@@ -183,23 +188,13 @@
void setLengthWritable(ExecState*, bool writable);
};
-inline Butterfly* createContiguousArrayButterfly(VM& vm, JSCell* intendedOwner, unsigned length, unsigned& vectorLength)
+inline Butterfly* tryCreateArrayButterfly(VM& vm, JSCell* intendedOwner, unsigned initialLength)
{
- IndexingHeader header;
- vectorLength = Butterfly::optimalContiguousVectorLength(
- intendedOwner ? intendedOwner->structure(vm) : 0, length);
- header.setVectorLength(vectorLength);
- header.setPublicLength(length);
- Butterfly* result = Butterfly::create(
- vm, intendedOwner, 0, 0, true, header, vectorLength * sizeof(EncodedJSValue));
- return result;
-}
-
-inline Butterfly* createArrayButterfly(VM& vm, JSCell* intendedOwner, unsigned initialLength)
-{
- Butterfly* butterfly = Butterfly::create(
+ Butterfly* butterfly = Butterfly::tryCreate(
vm, intendedOwner, 0, 0, true, baseIndexingHeaderForArrayStorage(initialLength),
ArrayStorage::sizeFor(BASE_ARRAY_STORAGE_VECTOR_LEN));
+ if (!butterfly)
+ return nullptr;
ArrayStorage* storage = butterfly->arrayStorage();
storage->m_sparseMap.clear();
storage->m_indexBias = 0;
@@ -207,29 +202,50 @@
return butterfly;
}
+inline Butterfly* createArrayButterfly(VM& vm, JSCell* intendedOwner, unsigned initialLength)
+{
+ Butterfly* result = tryCreateArrayButterfly(vm, intendedOwner, initialLength);
+ RELEASE_ASSERT(result);
+ return result;
+}
+
Butterfly* createArrayButterflyInDictionaryIndexingMode(
VM&, JSCell* intendedOwner, unsigned initialLength);
-inline JSArray* JSArray::create(VM& vm, Structure* structure, unsigned initialLength)
+inline JSArray* JSArray::tryCreate(VM& vm, Structure* structure, unsigned initialLength)
{
+ unsigned outOfLineStorage = structure->outOfLineCapacity();
+
Butterfly* butterfly;
- if (LIKELY(!hasAnyArrayStorage(structure->indexingType()))) {
+ IndexingType indexingType = structure->indexingType();
+ if (LIKELY(!hasAnyArrayStorage(indexingType))) {
ASSERT(
- hasUndecided(structure->indexingType())
- || hasInt32(structure->indexingType())
- || hasDouble(structure->indexingType())
- || hasContiguous(structure->indexingType()));
- unsigned vectorLength;
- butterfly = createContiguousArrayButterfly(vm, 0, initialLength, vectorLength);
- if (hasDouble(structure->indexingType()))
+ hasUndecided(indexingType)
+ || hasInt32(indexingType)
+ || hasDouble(indexingType)
+ || hasContiguous(indexingType));
+
+ if (initialLength > MAX_STORAGE_VECTOR_LENGTH)
+ return 0;
+
+ unsigned vectorLength = Butterfly::optimalContiguousVectorLength(structure, initialLength);
+ void* temp = vm.auxiliarySpace.tryAllocate(nullptr, Butterfly::totalSize(0, outOfLineStorage, true, vectorLength * sizeof(EncodedJSValue)));
+ if (!temp)
+ return nullptr;
+ butterfly = Butterfly::fromBase(temp, 0, outOfLineStorage);
+ butterfly->setVectorLength(vectorLength);
+ butterfly->setPublicLength(initialLength);
+ if (hasDouble(indexingType))
clearArray(butterfly->contiguousDouble().data(), vectorLength);
else
clearArray(butterfly->contiguous().data(), vectorLength);
} else {
ASSERT(
- structure->indexingType() == ArrayWithSlowPutArrayStorage
- || structure->indexingType() == ArrayWithArrayStorage);
- butterfly = createArrayButterfly(vm, 0, initialLength);
+ indexingType == ArrayWithSlowPutArrayStorage
+ || indexingType == ArrayWithArrayStorage);
+ butterfly = tryCreateArrayButterfly(vm, 0, initialLength);
+ if (!butterfly)
+ return nullptr;
for (unsigned i = 0; i < BASE_ARRAY_STORAGE_VECTOR_LEN; ++i)
butterfly->arrayStorage()->m_vector[i].clear();
}
@@ -237,6 +253,14 @@
return createWithButterfly(vm, nullptr, structure, butterfly);
}
+inline JSArray* JSArray::create(VM& vm, Structure* structure, unsigned initialLength)
+{
+ JSArray* result = JSArray::tryCreate(vm, structure, initialLength);
+ RELEASE_ASSERT(result);
+
+ return result;
+}
+
inline JSArray* JSArray::createWithButterfly(VM& vm, GCDeferralContext* deferralContext, Structure* structure, Butterfly* butterfly)
{
JSArray* array = new (NotNull, allocateCell<JSArray>(vm.heap, deferralContext)) JSArray(vm, structure, butterfly);