Changeset 224122 in webkit
- Timestamp:
- Oct 27, 2017 11:42:27 AM (6 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r224072 r224122 1 2017-10-27 JF Bastien <jfbastien@apple.com> 2 3 WebAssembly: update arbitrary limits to what browsers use 4 https://bugs.webkit.org/show_bug.cgi?id=178946 5 <rdar://problem/34257412> 6 <rdar://problem/34501154> 7 8 Reviewed by Saam Barati. 9 10 https://github.com/WebAssembly/design/issues/1138 discusses the 11 arbitrary function size limit, which it turns out Chrome and 12 Firefox didn't enforce. We didn't use it because it was 13 ridiculously low and actual programs ran into that limit (bummer 14 for Edge which just shipped it...). Now that we agree on a high 15 arbitrary program limit, let's update it! While I'm doing this 16 there are a few other spots that I polished to use Checked or 17 better check limits overall. 18 19 * wasm/WasmB3IRGenerator.cpp: 20 (JSC::Wasm::B3IRGenerator::addLocal): 21 * wasm/WasmFormat.cpp: 22 (JSC::Wasm::Segment::create): 23 * wasm/WasmFunctionParser.h: 24 (JSC::Wasm::FunctionParser<Context>::parse): 25 * wasm/WasmInstance.cpp: 26 * wasm/WasmLimits.h: 27 * wasm/WasmModuleParser.cpp: 28 (JSC::Wasm::ModuleParser::parseGlobal): 29 (JSC::Wasm::ModuleParser::parseCode): 30 (JSC::Wasm::ModuleParser::parseData): 31 * wasm/WasmSignature.h: 32 (JSC::Wasm::Signature::allocatedSize): 33 * wasm/WasmTable.cpp: 34 (JSC::Wasm::Table::Table): 35 * wasm/js/JSWebAssemblyTable.cpp: 36 (JSC::JSWebAssemblyTable::JSWebAssemblyTable): 37 (JSC::JSWebAssemblyTable::grow): 38 1 39 2017-10-26 Michael Saboff <msaboff@apple.com> 2 40 -
trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp
r224020 r224122 512 512 auto B3IRGenerator::addLocal(Type type, uint32_t count) -> PartialResult 513 513 { 514 WASM_COMPILE_FAIL_IF(!m_locals.tryReserveCapacity(m_locals.size() + count), "can't allocate memory for ", m_locals.size() + count, " locals"); 514 Checked<uint32_t, RecordOverflow> totalBytesChecked = count; 515 totalBytesChecked += m_locals.size(); 516 uint32_t totalBytes; 517 WASM_COMPILE_FAIL_IF((totalBytesChecked.safeGet(totalBytes) == CheckedState::DidOverflow) || !m_locals.tryReserveCapacity(totalBytes), "can't allocate memory for ", totalBytes, " locals"); 515 518 516 519 for (uint32_t i = 0; i < count; ++i) { -
trunk/Source/JavaScriptCore/wasm/WasmFormat.cpp
r216597 r224122 31 31 32 32 #include "WasmMemory.h" 33 #include <wtf/CheckedArithmetic.h> 33 34 #include <wtf/FastMalloc.h> 34 35 … … 37 38 Segment* Segment::create(I32InitExpr offset, uint32_t sizeInBytes) 38 39 { 39 auto allocated = tryFastCalloc(sizeof(Segment) + sizeInBytes, 1); 40 Checked<uint32_t, RecordOverflow> totalBytesChecked = sizeInBytes; 41 totalBytesChecked += sizeof(Segment); 42 uint32_t totalBytes; 43 if (totalBytesChecked.safeGet(totalBytes) == CheckedState::DidOverflow) 44 return nullptr; 45 auto allocated = tryFastCalloc(totalBytes, 1); 40 46 Segment* segment; 41 47 if (!allocated.getValue(segment)) -
trunk/Source/JavaScriptCore/wasm/WasmFunctionParser.h
r220894 r224122 113 113 WASM_PARSER_FAIL_IF(!m_context.addArguments(m_signature), "can't add ", m_signature.argumentCount(), " arguments to Function"); 114 114 WASM_PARSER_FAIL_IF(!parseVarUInt32(localCount), "can't get local count"); 115 WASM_PARSER_FAIL_IF(localCount == std::numeric_limits<uint32_t>::max(), "Function section's local count is too big ", localCount);115 WASM_PARSER_FAIL_IF(localCount > maxFunctionLocals, "Function section's local count is too big ", localCount, " maximum ", maxFunctionLocals); 116 116 117 117 for (uint32_t i = 0; i < localCount; ++i) { … … 120 120 121 121 WASM_PARSER_FAIL_IF(!parseVarUInt32(numberOfLocals), "can't get Function's number of locals in group ", i); 122 WASM_PARSER_FAIL_IF(numberOfLocals == std::numeric_limits<uint32_t>::max(), "Function section's ", i, "th local group count is too big ", numberOfLocals);122 WASM_PARSER_FAIL_IF(numberOfLocals > maxFunctionLocals, "Function section's ", i, "th local group count is too big ", numberOfLocals, " maximum ", maxFunctionLocals); 123 123 WASM_PARSER_FAIL_IF(!parseValueType(typeOfLocal), "can't get Function local's type in group ", i); 124 124 WASM_TRY_ADD_TO_CONTEXT(addLocal(typeOfLocal, numberOfLocals)); -
trunk/Source/JavaScriptCore/wasm/WasmInstance.cpp
r224020 r224122 27 27 #include "WasmInstance.h" 28 28 29 #if ENABLE(WEBASSEMBLY) 30 29 31 #include "Register.h" 30 32 #include "WasmModuleInformation.h" 31 32 #if ENABLE(WEBASSEMBLY) 33 #include <wtf/CheckedArithmetic.h> 33 34 34 35 namespace JSC { namespace Wasm { … … 37 38 size_t globalMemoryByteSize(Module& module) 38 39 { 39 return module.moduleInformation().globals.size() * sizeof(Register);40 return (Checked<size_t>(module.moduleInformation().globals.size()) * sizeof(Register)).unsafeGet(); 40 41 } 41 42 } -
trunk/Source/JavaScriptCore/wasm/WasmLimits.h
r216921 r224122 47 47 constexpr size_t maxStringSize = 100000; 48 48 constexpr size_t maxModuleSize = 1024 * 1024 * 1024; 49 constexpr size_t maxFunctionSize = 7654321; 50 constexpr size_t maxFunctionLocals = 50000; 49 51 constexpr size_t maxFunctionParams = 1000; 50 52 -
trunk/Source/JavaScriptCore/wasm/WasmModuleParser.cpp
r223738 r224122 341 341 WASM_PARSER_FAIL_IF(!parseVarUInt32(globalCount), "can't get Global section's count"); 342 342 WASM_PARSER_FAIL_IF(globalCount > maxGlobals, "Global section's count is too big ", globalCount, " maximum ", maxGlobals); 343 WASM_PARSER_FAIL_IF(!m_info->globals.tryReserveCapacity(globalCount + m_info->firstInternalGlobal), "can't allocate memory for ", globalCount + m_info->firstInternalGlobal, " globals"); 343 size_t totalBytes = globalCount + m_info->firstInternalGlobal; 344 WASM_PARSER_FAIL_IF((static_cast<uint32_t>(totalBytes) < globalCount) || !m_info->globals.tryReserveCapacity(totalBytes), "can't allocate memory for ", totalBytes, " globals"); 344 345 345 346 for (uint32_t globalIndex = 0; globalIndex < globalCount; ++globalIndex) { … … 475 476 WASM_PARSER_FAIL_IF(functionSize > length(), "Code function's size ", functionSize, " exceeds the module's size ", length()); 476 477 WASM_PARSER_FAIL_IF(functionSize > length() - m_offset, "Code function's size ", functionSize, " exceeds the module's remaining size", length() - m_offset); 477 WASM_PARSER_FAIL_IF(functionSize > std::numeric_limits<uint32_t>::max(), "Code function's size ", functionSize, " is too big");478 WASM_PARSER_FAIL_IF(functionSize > maxFunctionSize, "Code function's size ", functionSize, " is too big"); 478 479 479 480 m_info->functionLocationInBinary[i].start = m_offset; … … 574 575 WASM_PARSER_FAIL_IF(initExprType != I32, segmentNumber, "th Data segment's init_expr must produce an i32"); 575 576 WASM_PARSER_FAIL_IF(!parseVarUInt32(dataByteLength), "can't get ", segmentNumber, "th Data segment's data byte length"); 576 WASM_PARSER_FAIL_IF(dataByteLength == std::numeric_limits<uint32_t>::max(), segmentNumber, "th Data segment's data byte length is too big ", dataByteLength);577 WASM_PARSER_FAIL_IF(dataByteLength > maxModuleSize, segmentNumber, "th Data segment's data byte length is too big ", dataByteLength, " maximum ", maxModuleSize); 577 578 578 579 Segment* segment = Segment::create(makeI32InitExpr(initOpcode, initExprBits), dataByteLength); -
trunk/Source/JavaScriptCore/wasm/WasmSignature.h
r223738 r224122 32 32 #include <cstdint> 33 33 #include <cstring> 34 #include <wtf/CheckedArithmetic.h> 34 35 #include <wtf/HashMap.h> 35 36 #include <wtf/HashTraits.h> … … 65 66 } 66 67 Type* storage(SignatureArgCount i) const { return const_cast<Signature*>(this)->storage(i); } 67 static size_t allocatedSize( SignatureArgCountargCount)68 static size_t allocatedSize(Checked<SignatureArgCount> argCount) 68 69 { 69 return sizeof(Signature) + (s_retCount + argCount) * sizeof(Type);70 return (sizeof(Signature) + (s_retCount + argCount) * sizeof(Type)).unsafeGet(); 70 71 } 71 72 -
trunk/Source/JavaScriptCore/wasm/WasmTable.cpp
r224020 r224122 55 55 // FIXME: It might be worth trying to pre-allocate maximum here. The spec recommends doing so. 56 56 // But for now, we're not doing that. 57 m_functions = MallocPtr<Wasm::CallableFunction>::malloc( sizeof(Wasm::CallableFunction) * static_cast<size_t>(size()));58 m_instances = MallocPtr<Instance*>::malloc( sizeof(Instance*) * static_cast<size_t>(size()));57 m_functions = MallocPtr<Wasm::CallableFunction>::malloc((sizeof(Wasm::CallableFunction) * Checked<size_t>(size())).unsafeGet()); 58 m_instances = MallocPtr<Instance*>::malloc((sizeof(Instance*) * Checked<size_t>(size())).unsafeGet()); 59 59 for (uint32_t i = 0; i < size(); ++i) { 60 60 new (&m_functions.get()[i]) CallableFunction(); -
trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.cpp
r224020 r224122 31 31 #include "JSCInlines.h" 32 32 #include "JSWebAssemblyInstance.h" 33 #include <wtf/CheckedArithmetic.h> 33 34 34 35 namespace JSC { … … 62 63 // FIXME: It might be worth trying to pre-allocate maximum here. The spec recommends doing so. 63 64 // But for now, we're not doing that. 64 m_jsFunctions = MallocPtr<WriteBarrier<JSObject>>::malloc( sizeof(WriteBarrier<JSObject>) * static_cast<size_t>(size()));65 m_jsFunctions = MallocPtr<WriteBarrier<JSObject>>::malloc((sizeof(WriteBarrier<JSObject>) * Checked<size_t>(size())).unsafeGet()); 65 66 for (uint32_t i = 0; i < size(); ++i) 66 67 new(&m_jsFunctions.get()[i]) WriteBarrier<JSObject>(); … … 101 102 102 103 size_t newSize = grew.value(); 103 m_jsFunctions.realloc( sizeof(WriteBarrier<JSObject>) * newSize);104 m_jsFunctions.realloc((sizeof(WriteBarrier<JSObject>) * Checked<size_t>(newSize)).unsafeGet()); 104 105 105 106 for (size_t i = oldSize; i < newSize; ++i)
Note: See TracChangeset
for help on using the changeset viewer.