Truly independent web browser
Tests/LibWeb: Add a test for the WebAssembly operand stack limit
Andreas Kling08ff7de4fbd1
diff --git a/Tests/LibWeb/Text/expected/Wasm/WebAssembly-operand-stack-limit.txt b/Tests/LibWeb/Text/expected/Wasm/WebAssembly-operand-stack-limit.txtnew file mode 100644index 00000000000..18c1098b90b--- /dev/null+++ b/Tests/LibWeb/Text/expected/Wasm/WebAssembly-operand-stack-limit.txt@@ -0,0 +1,3 @@+1000 slots: true+1048000 slots: true+1049000 slots: truediff --git a/Tests/LibWeb/Text/input/Wasm/WebAssembly-operand-stack-limit.html b/Tests/LibWeb/Text/input/Wasm/WebAssembly-operand-stack-limit.htmlnew file mode 100644index 00000000000..def64e70012--- /dev/null+++ b/Tests/LibWeb/Text/input/Wasm/WebAssembly-operand-stack-limit.html@@ -0,0 +1,50 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ function leb(value) {+ const bytes = [];+ do {+ let byte = value % 128;+ value = Math.floor(value / 128);+ if (value !== 0)+ byte |= 0x80;+ bytes.push(byte);+ } while (value !== 0);+ return bytes;+ }++ function section(id, contents) {+ return [id, ...leb(contents.length), ...contents];+ }++ // A module whose function 1 calls function 0, which returns 1000 i64 values, `callCount` times without+ // consuming any of the results, then drops into unreachable code so the function still validates.+ function moduleWithOperandStackHeight(callCount) {+ const types = [+ 0x02,+ 0x60, 0x00, ...leb(1000), ...new Array(1000).fill(0x7e),+ 0x60, 0x00, 0x00,+ ];+ const producer = [0x00, 0x00, 0x0b];+ const consumer = [0x00];+ for (let i = 0; i < callCount; ++i)+ consumer.push(0x10, 0x00);+ consumer.push(0x00, 0x0b);+ return new Uint8Array([+ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,+ ...section(1, types),+ ...section(3, [0x02, 0x00, 0x01]),+ ...section(10, [+ 0x02,+ ...leb(producer.length), ...producer,+ ...leb(consumer.length), ...consumer,+ ]),+ ]);+ }++ test(() => {+ println(`1000 slots: ${WebAssembly.validate(moduleWithOperandStackHeight(1))}`);+ println(`1048000 slots: ${WebAssembly.validate(moduleWithOperandStackHeight(1048))}`);+ println(`1049000 slots: ${WebAssembly.validate(moduleWithOperandStackHeight(1049))}`);+ });+</script>