Skip to content

Truly independent web browser

Tests/LibWeb: Add a test for the WebAssembly subtyping depth limit

Andreas Kling6d997d56e4d5
diff --git a/Tests/LibWeb/Text/expected/Wasm/WebAssembly-subtyping-depth-limit.txt b/Tests/LibWeb/Text/expected/Wasm/WebAssembly-subtyping-depth-limit.txt
new file mode 100644
index 00000000000..f41a924460d
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/Wasm/WebAssembly-subtyping-depth-limit.txt
@@ -0,0 +1,2 @@
+Subtyping depth 63: true
+Subtyping depth 64: true
diff --git a/Tests/LibWeb/Text/input/Wasm/WebAssembly-subtyping-depth-limit.html b/Tests/LibWeb/Text/input/Wasm/WebAssembly-subtyping-depth-limit.html
new file mode 100644
index 00000000000..395cc27f587
--- /dev/null
+++ b/Tests/LibWeb/Text/input/Wasm/WebAssembly-subtyping-depth-limit.html
@@ -0,0 +1,34 @@
+<!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 with a chain of `count` struct types, each a subtype of the one before it.
+ function moduleWithSubtypeChain(count) {
+ const types = [...leb(count)];
+ for (let index = 0; index < count; ++index) {
+ const supertypes = index === 0 ? [0x00] : [0x01, ...leb(index - 1)];
+ types.push(0x50, ...supertypes, 0x5f, 0x00);
+ }
+ return new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, ...section(1, types)]);
+ }
+
+ test(() => {
+ println(`Subtyping depth 63: ${WebAssembly.validate(moduleWithSubtypeChain(64))}`);
+ println(`Subtyping depth 64: ${WebAssembly.validate(moduleWithSubtypeChain(65))}`);
+ });
+</script>