Backed out changeset 664f0ef11e26 (bug 1598149) as per dev's request

This commit is contained in:
Dorel Luca 2019-11-26 20:57:31 +02:00
parent ad3b40a6b8
commit 5758a8c26c
3 changed files with 29 additions and 34 deletions

View File

@ -1,4 +1,8 @@
const { Module, Instance, Memory, Table, LinkError, RuntimeError } = WebAssembly; const Module = WebAssembly.Module;
const Instance = WebAssembly.Instance;
const Memory = WebAssembly.Memory;
const Table = WebAssembly.Table;
const LinkError = WebAssembly.LinkError;
const mem1Page = new Memory({initial:1}); const mem1Page = new Memory({initial:1});
const mem1PageMax1 = new Memory({initial:1, maximum: 1}); const mem1PageMax1 = new Memory({initial:1, maximum: 1});
@ -15,14 +19,6 @@ const tab2Elem = new Table({initial:2, element:"funcref"});
const tab3Elem = new Table({initial:3, element:"funcref"}); const tab3Elem = new Table({initial:3, element:"funcref"});
const tab4Elem = new Table({initial:4, element:"funcref"}); const tab4Elem = new Table({initial:4, element:"funcref"});
function assertSegmentFitError(f) {
if (wasmBulkMemSupported()) {
assertErrorMessage(f, RuntimeError, /out of bounds/);
} else {
assertErrorMessage(f, LinkError, /segment does not fit/);
}
}
// Memory size consistency and internal limits. // Memory size consistency and internal limits.
assertErrorMessage(() => new Memory({initial:2, maximum:1}), RangeError, /bad Memory maximum size/); assertErrorMessage(() => new Memory({initial:2, maximum:1}), RangeError, /bad Memory maximum size/);
@ -495,15 +491,15 @@ var m = new Module(wasmTextToBinary(`
`)); `));
assertEq(new Instance(m, {glob:{a:0}}) instanceof Instance, true); assertEq(new Instance(m, {glob:{a:0}}) instanceof Instance, true);
assertEq(new Instance(m, {glob:{a:(64*1024 - 2)}}) instanceof Instance, true); assertEq(new Instance(m, {glob:{a:(64*1024 - 2)}}) instanceof Instance, true);
assertSegmentFitError(() => new Instance(m, {glob:{a:(64*1024 - 1)}})); assertErrorMessage(() => new Instance(m, {glob:{a:(64*1024 - 1)}}), LinkError, /data segment does not fit/);
assertSegmentFitError(() => new Instance(m, {glob:{a:64*1024}})); assertErrorMessage(() => new Instance(m, {glob:{a:64*1024}}), LinkError, /data segment does not fit/);
var m = new Module(wasmTextToBinary(` var m = new Module(wasmTextToBinary(`
(module (module
(memory 1) (memory 1)
(data (i32.const 0x10001) "\\0a\\0b")) (data (i32.const 0x10001) "\\0a\\0b"))
`)); `));
assertSegmentFitError(() => new Instance(m)); assertErrorMessage(() => new Instance(m), LinkError, /data segment does not fit/);
var m = new Module(wasmTextToBinary(` var m = new Module(wasmTextToBinary(`
(module (module
@ -548,7 +544,9 @@ var mem = new Memory({initial:npages});
var mem8 = new Uint8Array(mem.buffer); var mem8 = new Uint8Array(mem.buffer);
var tbl = new Table({initial:2, element:"funcref"}); var tbl = new Table({initial:2, element:"funcref"});
assertSegmentFitError(() => new Instance(m, {a:{mem, tbl, memOff:1, tblOff:2}})); assertErrorMessage(() => new Instance(m, {a:{mem, tbl, memOff:1, tblOff:2}}),
LinkError,
/elem segment does not fit/);
if (wasmBulkMemSupported()) { if (wasmBulkMemSupported()) {
// The first active element segment is applied, but the second active // The first active element segment is applied, but the second active
// element segment is completely OOB. // element segment is completely OOB.
@ -564,7 +562,9 @@ assertEq(mem8[1], 0);
tbl.set(0, null); tbl.set(0, null);
tbl.set(1, null); tbl.set(1, null);
assertSegmentFitError(() => new Instance(m, {a:{mem, tbl, memOff:npages*64*1024, tblOff:1}})); assertErrorMessage(() => new Instance(m, {a:{mem, tbl, memOff:npages*64*1024, tblOff:1}}),
LinkError,
/data segment does not fit/);
if (wasmBulkMemSupported()) { if (wasmBulkMemSupported()) {
// The first and second active element segments are applied fully. The // The first and second active element segments are applied fully. The
// first active data segment applies, but the second one is completely OOB. // first active data segment applies, but the second one is completely OOB.
@ -605,7 +605,9 @@ if (wasmBulkMemSupported()) {
(func $h))`)); (func $h))`));
let mem = new Memory({initial:1}); let mem = new Memory({initial:1});
let tbl = new Table({initial:3, element:"funcref"}); let tbl = new Table({initial:3, element:"funcref"});
assertSegmentFitError(() => new Instance(m, {"":{mem, tbl}})); assertErrorMessage(() => new Instance(m, {"":{mem, tbl}}),
LinkError,
/elem segment does not fit/);
assertEq(tbl.get(0), null); assertEq(tbl.get(0), null);
assertEq(tbl.get(1), null); assertEq(tbl.get(1), null);
assertEq(tbl.get(2), null); assertEq(tbl.get(2), null);
@ -624,7 +626,9 @@ if (wasmBulkMemSupported()) {
(data (i32.const 0) "\\04") ;; is not applied (data (i32.const 0) "\\04") ;; is not applied
)`)); )`));
let mem = new Memory({initial:1}); let mem = new Memory({initial:1});
assertSegmentFitError(() => new Instance(m, {"":{mem}})); assertErrorMessage(() => new Instance(m, {"":{mem}}),
LinkError,
/data segment does not fit/);
let v = new Uint8Array(mem.buffer); let v = new Uint8Array(mem.buffer);
assertEq(v[65534], 0); assertEq(v[65534], 0);
assertEq(v[65535], 0); assertEq(v[65535], 0);

View File

@ -7,14 +7,6 @@ const RuntimeError = WebAssembly.RuntimeError;
const badFuncRefError = /can only pass WebAssembly exported functions to funcref/; const badFuncRefError = /can only pass WebAssembly exported functions to funcref/;
function assertSegmentFitError(f) {
if (wasmBulkMemSupported()) {
assertErrorMessage(f, RuntimeError, /out of bounds/);
} else {
assertErrorMessage(f, LinkError, /segment does not fit/);
}
}
var callee = i => `(func $f${i} (result i32) (i32.const ${i}))`; var callee = i => `(func $f${i} (result i32) (i32.const ${i}))`;
wasmFailValidateText(`(module (elem (i32.const 0) $f0) ${callee(0)})`, /elem segment requires a table/); wasmFailValidateText(`(module (elem (i32.const 0) $f0) ${callee(0)})`, /elem segment requires a table/);
@ -22,12 +14,12 @@ wasmFailValidateText(`(module (table 10 funcref) (elem (i32.const 0) 0))`, /tabl
wasmFailValidateText(`(module (table 10 funcref) (func) (elem (i32.const 0) 0 1))`, /table element out of range/); wasmFailValidateText(`(module (table 10 funcref) (func) (elem (i32.const 0) 0 1))`, /table element out of range/);
wasmFailValidateText(`(module (table 10 funcref) (func) (elem (f32.const 0) 0) ${callee(0)})`, /type mismatch/); wasmFailValidateText(`(module (table 10 funcref) (func) (elem (f32.const 0) 0) ${callee(0)})`, /type mismatch/);
assertSegmentFitError(() => wasmEvalText(`(module (table 10 funcref) (elem (i32.const 10) $f0) ${callee(0)})`)); assertErrorMessage(() => wasmEvalText(`(module (table 10 funcref) (elem (i32.const 10) $f0) ${callee(0)})`), LinkError, /elem segment does not fit/);
assertSegmentFitError(() => wasmEvalText(`(module (table 10 funcref) (elem (i32.const 8) $f0 $f0 $f0) ${callee(0)})`)); assertErrorMessage(() => wasmEvalText(`(module (table 10 funcref) (elem (i32.const 8) $f0 $f0 $f0) ${callee(0)})`), LinkError, /elem segment does not fit/);
assertSegmentFitError(() => wasmEvalText(`(module (table 0 funcref) (func) (elem (i32.const 0x10001)))`)); assertEq(wasmEvalText(`(module (table 0 funcref) (func) (elem (i32.const 0x10001)))`) instanceof Instance, true);
assertSegmentFitError(() => wasmEvalText(`(module (table 10 funcref) (import "globals" "a" (global i32)) (elem (global.get 0) $f0) ${callee(0)})`, {globals:{a:10}})); assertErrorMessage(() => wasmEvalText(`(module (table 10 funcref) (import "globals" "a" (global i32)) (elem (global.get 0) $f0) ${callee(0)})`, {globals:{a:10}}), LinkError, /elem segment does not fit/);
assertSegmentFitError(() => wasmEvalText(`(module (table 10 funcref) (import "globals" "a" (global i32)) (elem (global.get 0) $f0 $f0 $f0) ${callee(0)})`, {globals:{a:8}})); assertErrorMessage(() => wasmEvalText(`(module (table 10 funcref) (import "globals" "a" (global i32)) (elem (global.get 0) $f0 $f0 $f0) ${callee(0)})`, {globals:{a:8}}), LinkError, /elem segment does not fit/);
assertEq(new Module(wasmTextToBinary(`(module (table 10 funcref) (elem (i32.const 1) $f0 $f0) (elem (i32.const 0) $f0) ${callee(0)})`)) instanceof Module, true); assertEq(new Module(wasmTextToBinary(`(module (table 10 funcref) (elem (i32.const 1) $f0 $f0) (elem (i32.const 0) $f0) ${callee(0)})`)) instanceof Module, true);
assertEq(new Module(wasmTextToBinary(`(module (table 10 funcref) (elem (i32.const 1) $f0 $f0) (elem (i32.const 2) $f0) ${callee(0)})`)) instanceof Module, true); assertEq(new Module(wasmTextToBinary(`(module (table 10 funcref) (elem (i32.const 1) $f0 $f0) (elem (i32.const 2) $f0) ${callee(0)})`)) instanceof Module, true);
@ -69,7 +61,7 @@ var m = new Module(wasmTextToBinary(`
`)); `));
var tbl = new Table({initial:50, element:"funcref"}); var tbl = new Table({initial:50, element:"funcref"});
assertEq(new Instance(m, {globals:{a:20, table:tbl}}) instanceof Instance, true); assertEq(new Instance(m, {globals:{a:20, table:tbl}}) instanceof Instance, true);
assertSegmentFitError(() => new Instance(m, {globals:{a:50, table:tbl}})); assertErrorMessage(() => new Instance(m, {globals:{a:50, table:tbl}}), LinkError, /elem segment does not fit/);
var caller = `(type $v2i (func (result i32))) (func $call (param $i i32) (result i32) (call_indirect $v2i (local.get $i))) (export "call" $call)` var caller = `(type $v2i (func (result i32))) (func $call (param $i i32) (result i32) (call_indirect $v2i (local.get $i))) (export "call" $call)`
var callee = i => `(func $f${i} (type $v2i) (i32.const ${i}))`; var callee = i => `(func $f${i} (type $v2i) (i32.const ${i}))`;

View File

@ -531,8 +531,7 @@ bool Module::initSegments(JSContext* cx, HandleWasmInstanceObject instanceObj,
if (eagerBoundsCheck) { if (eagerBoundsCheck) {
// Perform all error checks up front so that this function does not perform // Perform all error checks up front so that this function does not perform
// partial initialization if an error is reported. In addition, we need to // partial initialization if an error is reported.
// to report OOBs as a link error when bulk-memory is disabled.
for (const ElemSegment* seg : elemSegments_) { for (const ElemSegment* seg : elemSegments_) {
if (!seg->active()) { if (!seg->active()) {
@ -587,7 +586,7 @@ bool Module::initSegments(JSContext* cx, HandleWasmInstanceObject instanceObj,
uint32_t tableLength = tables[seg->tableIndex]->length(); uint32_t tableLength = tables[seg->tableIndex]->length();
if (offset > tableLength || tableLength - offset < count) { if (offset > tableLength || tableLength - offset < count) {
JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr,
JSMSG_WASM_OUT_OF_BOUNDS); JSMSG_WASM_BAD_FIT, "elem", "table");
return false; return false;
} }
} }
@ -622,7 +621,7 @@ bool Module::initSegments(JSContext* cx, HandleWasmInstanceObject instanceObj,
if (!eagerBoundsCheck) { if (!eagerBoundsCheck) {
if (offset > memoryLength || memoryLength - offset < count) { if (offset > memoryLength || memoryLength - offset < count) {
JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr,
JSMSG_WASM_OUT_OF_BOUNDS); JSMSG_WASM_BAD_FIT, "data", "memory");
return false; return false;
} }
} }