Commit f87505ca authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm][bigint] Allow only bigints as i64-global imports

The fuzzer found a crash when we want to execute the {valueOf} function
of an imported value for an i64-global. The problem is that we cannot
execute JavaScript at that moment (I did not check why, I guess we open
some scope at some point). I checked the WebAssembly spec now, and it
defines that only numbers are valid values for imported globals. I
adjust our bigint implementation accordingly with this CL, i.e. that
only bigint values are valid as imported i64-globalsl.
I also created github issues to discuss this problem.

R=jkummerow@chromium.org

Bug: chromium:1001804
Change-Id: I47f0b31fab53163346f341ad290fd3c58e7707bf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1792167
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63621}
parent 6165355e
...@@ -1185,13 +1185,8 @@ bool InstanceBuilder::ProcessImportedGlobal(Handle<WasmInstanceObject> instance, ...@@ -1185,13 +1185,8 @@ bool InstanceBuilder::ProcessImportedGlobal(Handle<WasmInstanceObject> instance,
return true; return true;
} }
if (enabled_.bigint && global.type == kWasmI64) { if (enabled_.bigint && global.type == kWasmI64 && value->IsBigInt()) {
Handle<BigInt> bigint; WriteGlobalValue(global, BigInt::cast(*value).AsInt64());
if (!BigInt::FromObject(isolate_, value).ToHandle(&bigint)) {
return false;
}
WriteGlobalValue(global, bigint->AsInt64());
return true; return true;
} }
......
...@@ -26,30 +26,30 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -26,30 +26,30 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
let a_global_index = builder let a_global_index = builder
.addImportedGlobal("mod", "a", kWasmI64) .addImportedGlobal("mod", "a", kWasmI64);
let b_global_index = builder let b_global_index = builder
.addImportedGlobal("mod", "b", kWasmI64); .addImportedGlobal("mod", "b", kWasmI64);
let c_global_index = builder
.addImportedGlobal("mod", "c", kWasmI64);
builder builder
.addExportOfKind('a', kExternalGlobal, a_global_index) .addExportOfKind('a', kExternalGlobal, a_global_index)
.addExportOfKind('b', kExternalGlobal, b_global_index) .addExportOfKind('b', kExternalGlobal, b_global_index)
.addExportOfKind('c', kExternalGlobal, c_global_index);
let module = builder.instantiate({ let module = builder.instantiate({
mod: { mod: {
a: 1n, a: 1n,
b: 2n ** 63n, b: 2n ** 63n,
c: "123",
} }
}); });
assertEquals(module.exports.a.value, 1n); assertEquals(module.exports.a.value, 1n);
assertEquals(module.exports.b.value, - (2n ** 63n)); assertEquals(module.exports.b.value, - (2n ** 63n));
assertEquals(module.exports.c.value, 123n); })();
(function TestJSBigIntGlobalImportInvalidType() {
let builder = new WasmModuleBuilder();
builder.addImportedGlobal("mod", "a", kWasmI64);
assertThrows(() => builder.instantiate({mod: { a: {} } }), WebAssembly.LinkError);
})(); })();
(function TestJSBigIntToWasmI64MutableGlobal() { (function TestJSBigIntToWasmI64MutableGlobal() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment