Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Unified Diff: third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp

Issue 2702953002: [wasm] Block compile/instantiate of large array buffers (Closed)
Patch Set: Updated after V8 side landed Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/wasm/wasm-module-builder.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp b/third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp
index a0c4d830b0038274700ce939d2a12684a327e4e6..24672e13ea46cfa2f6d676f3317f218401c5da6c 100644
--- a/third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp
@@ -142,6 +142,9 @@ MessageLevel MessageLevelFromNonFatalErrorLevel(int errorLevel) {
}
return level;
}
+
+const size_t kWasmWireBytesLimit = 1 << 12;
Eden Wang 2017/02/23 08:50:03 Hi mtrodfin, Why choose this value? In mo
+
} // namespace
void V8Initializer::messageHandlerInMainThread(v8::Local<v8::Message> message,
@@ -319,6 +322,48 @@ static bool codeGenerationCheckCallbackInMainThread(
return false;
}
+static bool allowWasmCompileCallbackInMainThread(v8::Isolate* isolate,
+ v8::Local<v8::Value> source,
+ bool asPromise) {
+ // We allow async compilation irrespective of buffer size.
+ if (asPromise)
+ return true;
+ if (source->IsArrayBuffer() &&
+ v8::Local<v8::ArrayBuffer>::Cast(source)->ByteLength() >
+ kWasmWireBytesLimit) {
+ return false;
+ }
+ if (source->IsArrayBufferView() &&
+ v8::Local<v8::ArrayBufferView>::Cast(source)->ByteLength() >
+ kWasmWireBytesLimit) {
+ return false;
+ }
+ return true;
+}
+
+static bool allowWasmInstantiateCallbackInMainThread(
+ v8::Isolate* isolate,
+ v8::Local<v8::Value> source,
+ v8::MaybeLocal<v8::Value> ffi,
+ bool asPromise) {
+ // Async cases are allowed, regardless of the size of the
+ // wire bytes. Note that, for instantiation, we use the wire
+ // bytes size as a proxy for instantiation time. We may
+ // consider using the size of the ffi (nr of properties)
+ // instead, or, even more directly, number of imports.
+ if (asPromise)
+ return true;
+ // If it's not a promise, the source should be a wasm module
+ DCHECK(source->IsWebAssemblyCompiledModule());
+ v8::Local<v8::WasmCompiledModule> module =
+ v8::Local<v8::WasmCompiledModule>::Cast(source);
+ if (static_cast<size_t>(module->GetWasmWireBytes()->Length()) >
+ kWasmWireBytesLimit) {
+ return false;
+ }
+ return true;
+}
+
static void initializeV8Common(v8::Isolate* isolate) {
isolate->AddGCPrologueCallback(V8GCController::gcPrologue);
isolate->AddGCEpilogueCallback(V8GCController::gcEpilogue);
@@ -414,7 +459,9 @@ void V8Initializer::initializeMainThread() {
failedAccessCheckCallbackInMainThread);
isolate->SetAllowCodeGenerationFromStringsCallback(
codeGenerationCheckCallbackInMainThread);
-
+ isolate->SetAllowWasmCompileCallback(allowWasmCompileCallbackInMainThread);
+ isolate->SetAllowWasmInstantiateCallback(
+ allowWasmInstantiateCallbackInMainThread);
if (RuntimeEnabledFeatures::v8IdleTasksEnabled()) {
V8PerIsolateData::enableIdleTasks(
isolate, WTF::makeUnique<V8IdleTaskRunner>(scheduler));
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/wasm/wasm-module-builder.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698