Skip to content

Commit 441e6d4

Browse files
gahaasCommit Bot
authored andcommitted
[wasm] Do an additional IsWasmModuleObject check during instantiation
When WebAssembly.instantiate or WebAssembly.instantiateStreaming is called in JavaScript, internally we transfrom it into WebAssembly.compile(buffer).then(WebAssembly.instantiate). However, modifying the prototype of WebAssembly.Module can change the result of WebAssembly.compile(buffer). With this CL we make sure that even if the result of WebAssembly.compile is modified, there is still no type confusion. In the long term we have to do a refactoring and remove this internal transformation. [email protected] Bug: chromium:837417 Change-Id: I376068b8b8b01b991ec450162da6a62ae7030c62 Reviewed-on: https://chromium-review.googlesource.com/1032392 Commit-Queue: Andreas Haas <[email protected]> Reviewed-by: Michael Starzinger <[email protected]> Cr-Commit-Position: refs/heads/master@{#52859}
1 parent 8e102e0 commit 441e6d4

3 files changed

Lines changed: 34 additions & 6 deletions

File tree

src/wasm/wasm-js.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,16 +330,22 @@ MaybeLocal<Value> WebAssemblyInstantiateImpl(Isolate* isolate,
330330
i::MaybeHandle<i::Object> instance_object;
331331
{
332332
ScheduledErrorThrower thrower(i_isolate, "WebAssembly Instantiation");
333+
334+
// TODO(ahaas): These checks on the module should not be necessary here They
335+
// are just a workaround for https://crbug.com/837417.
336+
i::Handle<i::Object> module_obj = Utils::OpenHandle(*module);
337+
if (!module_obj->IsWasmModuleObject()) {
338+
thrower.TypeError("Argument 0 must be a WebAssembly.Module object");
339+
return {};
340+
}
341+
333342
i::MaybeHandle<i::JSReceiver> maybe_imports =
334343
GetValueAsImports(ffi, &thrower);
335344
if (thrower.error()) return {};
336345

337-
i::Handle<i::WasmModuleObject> module_obj =
338-
i::Handle<i::WasmModuleObject>::cast(
339-
Utils::OpenHandle(Object::Cast(*module)));
340346
instance_object = i_isolate->wasm_engine()->SyncInstantiate(
341-
i_isolate, &thrower, module_obj, maybe_imports,
342-
i::MaybeHandle<i::JSArrayBuffer>());
347+
i_isolate, &thrower, i::Handle<i::WasmModuleObject>::cast(module_obj),
348+
maybe_imports, i::MaybeHandle<i::JSArrayBuffer>());
343349
}
344350

345351
DCHECK_EQ(instance_object.is_null(), i_isolate->has_scheduled_exception());

test/mjsunit/regress/wasm/regress-836141.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ builder.addFunction("test", kSig_i_v).addBody([
1111
kExprI32Const, 12, // i32.const 0
1212
]);
1313

14-
let bla = 0;
1514
let module = new WebAssembly.Module(builder.toBuffer());
1615
module.then = () => {
1716
// Use setTimeout to get out of the promise chain.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2018 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
load('test/mjsunit/wasm/wasm-constants.js');
6+
load('test/mjsunit/wasm/wasm-module-builder.js');
7+
8+
const builder = new WasmModuleBuilder();
9+
builder.addMemory(16, 32);
10+
builder.addFunction("test", kSig_i_v).addBody([
11+
kExprI32Const, 12, // i32.const 0
12+
]);
13+
14+
WebAssembly.Module.prototype.then = resolve => resolve(
15+
String.fromCharCode(null, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41));
16+
17+
// WebAssembly.instantiate should not actually throw a TypeError in this case.
18+
// However, this is a workaround for
19+
assertPromiseResult(
20+
WebAssembly.instantiate(builder.toBuffer()), assertUnreachable,
21+
exception => {
22+
assertInstanceof(exception, TypeError);
23+
});

0 commit comments

Comments
 (0)