From 899ce6695d6555e1f3b9cdf3883bdbd2e8936372 Mon Sep 17 00:00:00 2001 From: Thomas Steiner Date: Mon, 24 Apr 2023 14:19:17 +0200 Subject: [PATCH 01/12] [js-api] Editorial: add grouping separators to limit values (#1643) --- document/js-api/index.bs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index c085e583..e31e47ab 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -1191,31 +1191,31 @@ An implementation must reject a module that exceeds one of the following limits In practice, an implementation may run out of resources for valid modules below these limits. An implementation must throw a {{RuntimeError}} if one of the following limits is exceeded during runtime: In practice, an implementation may run out of resources for valid modules below these limits.

Security and Privacy Considerations

From 49e87dc14e5e018bc30cb07d4ba54d6501f4de68 Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Thu, 27 Apr 2023 01:45:50 -0700 Subject: [PATCH 02/12] [test] Add test for init expr with missing end marker (#1645) --- test/core/binary.wast | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/core/binary.wast b/test/core/binary.wast index 526e0a20..4e748e70 100644 --- a/test/core/binary.wast +++ b/test/core/binary.wast @@ -470,6 +470,19 @@ "section size mismatch" ) +;; Init expression with missing end marker +(assert_malformed + (module binary + "\00asm" "\01\00\00\00" + "\01\04\01\60\00\00" ;; Type section: 1 type + "\03\02\01\00" ;; Function section: 1 function + "\06\05\01\7f\00\41\00" ;; Global section: 1 entry with missing end marker + ;; Missing end marker here + "\0a\04\01\02\00\0b" ;; Code section: 1 function + ) + "illegal opcode" +) + ;; Unsigned LEB128 must not be overlong (assert_malformed (module binary From dec27387d723ab7da2667f0dc36dd117eba844d9 Mon Sep 17 00:00:00 2001 From: gahaas Date: Tue, 2 May 2023 07:24:28 +0200 Subject: [PATCH 03/12] Add test for the module size limit (#1642) * Add test for the module size limit The limits test did not test the maximum supported module size of 1GB yet. This PR adds tests which create modules consisting of a single custom section. The first test checks if a module of size 1GB is allowed, the second test checks that a module of size 1GB + 1 byte gets rejected. * Some cleanup --- test/js-api/limits.any.js | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/js-api/limits.any.js b/test/js-api/limits.any.js index 7e690cad..91f058d6 100644 --- a/test/js-api/limits.any.js +++ b/test/js-api/limits.any.js @@ -244,3 +244,53 @@ test(() => { () => memory.grow(kJSEmbeddingMaxTableSize)); }, `Grow WebAssembly.Table object beyond the embedder-defined limit`); +function testModuleSizeLimit(size, expectPass) { + // We do not use `testLimit` here to avoid OOMs due to having multiple big + // modules alive at the same time. + + // Define a WebAssembly module that consists of a single custom section which + // has an empty name. The module size will be `size`. + const buffer = new Uint8Array(size); + const header = [ + kWasmH0, kWasmH1, kWasmH2, kWasmH3, // magic word + kWasmV0, kWasmV1, kWasmV2, kWasmV3, // version + 0 // custom section + ]; + // We calculate the section length so that the total module size is `size`. + // For that we have to calculate the length of the leb encoding of the section + // length. + const sectionLength = size - header.length - + wasmSignedLeb(size).length; + const lengthBytes = wasmSignedLeb(sectionLength); + buffer.set(header); + buffer.set(lengthBytes, header.length); + + if (expectPass) { + test(() => { + assert_true(WebAssembly.validate(buffer)); + }, `Validate module size limit`); + test(() => { + new WebAssembly.Module(buffer); + }, `Compile module size limit`); + promise_test(t => { + return WebAssembly.compile(buffer); + }, `Async compile module size limit`); + } else { + test(() => { + assert_false(WebAssembly.validate(buffer)); + }, `Validate module size over limit`); + test(() => { + assert_throws( + new WebAssembly.CompileError(), + () => new WebAssembly.Module(buffer)); + }, `Compile module size over limit`); + promise_test(t => { + return promise_rejects( + t, new WebAssembly.CompileError(), + WebAssembly.compile(buffer)); + }, `Async compile module size over limit`); + } +} + +testModuleSizeLimit(kJSEmbeddingMaxModuleSize, true); +testModuleSizeLimit(kJSEmbeddingMaxModuleSize + 1, false); From b72a1aae7f1a44e16178541b3107e49fba91cfe6 Mon Sep 17 00:00:00 2001 From: Clemens Backes Date: Wed, 10 May 2023 16:20:24 +0200 Subject: [PATCH 04/12] [test] Disable tests that become valid with memory64 (#1648) --- test/core/binary.wast | 237 ++++++++++++++++++++++-------------------- 1 file changed, 122 insertions(+), 115 deletions(-) diff --git a/test/core/binary.wast b/test/core/binary.wast index 4e748e70..1aae74aa 100644 --- a/test/core/binary.wast +++ b/test/core/binary.wast @@ -492,25 +492,27 @@ ) "integer representation too long" ) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\11\01" ;; Code section - ;; function 0 - "\0f\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\28" ;; i32.load - "\02" ;; alignment 2 - "\82\80\80\80\80\00" ;; offset 2 with one byte too many - "\1a" ;; drop - "\0b" ;; end - ) - "integer representation too long" -) +;; The memory offset will be decoded as u64 in the memory64 proposal. +;; TODO: Re-enable this test as assert_trap test in the memory64 repo. +;; (assert_malformed +;; (module binary +;; "\00asm" "\01\00\00\00" +;; "\01\04\01\60\00\00" ;; Type section +;; "\03\02\01\00" ;; Function section +;; "\05\03\01\00\01" ;; Memory section +;; "\0a\11\01" ;; Code section +;; ;; function 0 +;; "\0f\01\01" ;; local type count +;; "\7f" ;; i32 +;; "\41\00" ;; i32.const 0 +;; "\28" ;; i32.load +;; "\02" ;; alignment 2 +;; "\82\80\80\80\80\00" ;; offset 2 with one byte too many +;; "\1a" ;; drop +;; "\0b" ;; end +;; ) +;; "integer representation too long" +;; ) (assert_malformed (module binary "\00asm" "\01\00\00\00" @@ -549,25 +551,27 @@ ) "integer representation too long" ) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\12\01" ;; Code section - ;; function 0 - "\10\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\41\03" ;; i32.const 3 - "\36" ;; i32.store - "\02" ;; alignment 2 - "\82\80\80\80\80\00" ;; offset 2 with one byte too many - "\0b" ;; end - ) - "integer representation too long" -) +;; The memory offset will be decoded as u64 in the memory64 proposal. +;; TODO: Re-enable this test as assert_trap test in the memory64 repo. +;; (assert_malformed +;; (module binary +;; "\00asm" "\01\00\00\00" +;; "\01\04\01\60\00\00" ;; Type section +;; "\03\02\01\00" ;; Function section +;; "\05\03\01\00\01" ;; Memory section +;; "\0a\12\01" ;; Code section +;; ;; function 0 +;; "\10\01\01" ;; local type count +;; "\7f" ;; i32 +;; "\41\00" ;; i32.const 0 +;; "\41\03" ;; i32.const 3 +;; "\36" ;; i32.store +;; "\02" ;; alignment 2 +;; "\82\80\80\80\80\00" ;; offset 2 with one byte too many +;; "\0b" ;; end +;; ) +;; "integer representation too long" +;; ) ;; Signed LEB128 must not be overlong (assert_malformed @@ -629,44 +633,46 @@ ) "integer too large" ) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\10\01" ;; Code section - ;; function 0 - "\0e\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\28" ;; i32.load - "\02" ;; alignment 2 - "\82\80\80\80\10" ;; offset 2 with unused bits set - "\1a" ;; drop - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\10\01" ;; Code section - ;; function 0 - "\0e\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\28" ;; i32.load - "\02" ;; alignment 2 - "\82\80\80\80\40" ;; offset 2 with some unused bits set - "\1a" ;; drop - "\0b" ;; end - ) - "integer too large" -) +;; The memory offset will be decoded as u64 in the memory64 proposal. +;; TODO: Re-enable this test as assert_trap test in the memory64 repo. +;; (assert_malformed +;; (module binary +;; "\00asm" "\01\00\00\00" +;; "\01\04\01\60\00\00" ;; Type section +;; "\03\02\01\00" ;; Function section +;; "\05\03\01\00\01" ;; Memory section +;; "\0a\10\01" ;; Code section +;; ;; function 0 +;; "\0e\01\01" ;; local type count +;; "\7f" ;; i32 +;; "\41\00" ;; i32.const 0 +;; "\28" ;; i32.load +;; "\02" ;; alignment 2 +;; "\82\80\80\80\10" ;; offset 2 with unused bits set +;; "\1a" ;; drop +;; "\0b" ;; end +;; ) +;; "integer too large" +;; ) +;; (assert_malformed +;; (module binary +;; "\00asm" "\01\00\00\00" +;; "\01\04\01\60\00\00" ;; Type section +;; "\03\02\01\00" ;; Function section +;; "\05\03\01\00\01" ;; Memory section +;; "\0a\10\01" ;; Code section +;; ;; function 0 +;; "\0e\01\01" ;; local type count +;; "\7f" ;; i32 +;; "\41\00" ;; i32.const 0 +;; "\28" ;; i32.load +;; "\02" ;; alignment 2 +;; "\82\80\80\80\40" ;; offset 2 with some unused bits set +;; "\1a" ;; drop +;; "\0b" ;; end +;; ) +;; "integer too large" +;; ) (assert_malformed (module binary "\00asm" "\01\00\00\00" @@ -742,45 +748,46 @@ ) "integer too large" ) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\11\01" ;; Code section - ;; function 0 - "\0f\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\41\03" ;; i32.const 3 - "\36" ;; i32.store - "\02" ;; alignment 2 - "\82\80\80\80\10" ;; offset 2 with unused bits set - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\11\01" ;; Code section - - ;; function 0 - "\0f\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\41\03" ;; i32.const 3 - "\36" ;; i32.store - "\02" ;; alignment 2 - "\82\80\80\80\40" ;; offset 2 with some unused bits set - "\0b" ;; end - ) - "integer too large" -) +;; The memory offset will be decoded as u64 in the memory64 proposal. +;; TODO: Re-enable this test as assert_trap test in the memory64 repo. +;; (assert_malformed +;; (module binary +;; "\00asm" "\01\00\00\00" +;; "\01\04\01\60\00\00" ;; Type section +;; "\03\02\01\00" ;; Function section +;; "\05\03\01\00\01" ;; Memory section +;; "\0a\11\01" ;; Code section +;; ;; function 0 +;; "\0f\01\01" ;; local type count +;; "\7f" ;; i32 +;; "\41\00" ;; i32.const 0 +;; "\41\03" ;; i32.const 3 +;; "\36" ;; i32.store +;; "\02" ;; alignment 2 +;; "\82\80\80\80\10" ;; offset 2 with unused bits set +;; "\0b" ;; end +;; ) +;; "integer too large" +;; ) +;; (assert_malformed +;; (module binary +;; "\00asm" "\01\00\00\00" +;; "\01\04\01\60\00\00" ;; Type section +;; "\03\02\01\00" ;; Function section +;; "\05\03\01\00\01" ;; Memory section +;; "\0a\11\01" ;; Code section +;; ;; function 0 +;; "\0f\01\01" ;; local type count +;; "\7f" ;; i32 +;; "\41\00" ;; i32.const 0 +;; "\41\03" ;; i32.const 3 +;; "\36" ;; i32.store +;; "\02" ;; alignment 2 +;; "\82\80\80\80\40" ;; offset 2 with some unused bits set +;; "\0b" ;; end +;; ) +;; "integer too large" +;; ) ;; Signed LEB128s sign-extend (assert_malformed From 0a190c98bf18fe42de359e953a103651702b9d4a Mon Sep 17 00:00:00 2001 From: Clemens Backes Date: Wed, 10 May 2023 18:14:24 +0200 Subject: [PATCH 05/12] Remove duplicated binary tests (#1649) * Remove duplicated binary tests Those tests were moved to `binary-leb128.wast` in #1019, but #1287 brought them back. * Remove more duplicated tests --- test/core/binary.wast | 673 ------------------------------------------ 1 file changed, 673 deletions(-) diff --git a/test/core/binary.wast b/test/core/binary.wast index 1aae74aa..329b8a5a 100644 --- a/test/core/binary.wast +++ b/test/core/binary.wast @@ -51,95 +51,6 @@ (assert_malformed (module binary "\00asm" "\01\00\00\00" "\81\01\00\01\01\00") "malformed section id") (assert_malformed (module binary "\00asm" "\01\00\00\00" "\ff\01\00\01\01\00") "malformed section id") -;; Unsigned LEB128 can have non-minimal length -(module binary - "\00asm" "\01\00\00\00" - "\05\04\01" ;; Memory section with 1 entry - "\00\82\00" ;; no max, minimum 2 -) -(module binary - "\00asm" "\01\00\00\00" - "\05\07\01" ;; Memory section with 1 entry - "\00\82\80\80\80\00" ;; no max, minimum 2 -) - -;; Signed LEB128 can have non-minimal length -(module binary - "\00asm" "\01\00\00\00" - "\06\07\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\80\00" ;; i32.const 0 - "\0b" ;; end -) -(module binary - "\00asm" "\01\00\00\00" - "\06\07\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\ff\7f" ;; i32.const -1 - "\0b" ;; end -) -(module binary - "\00asm" "\01\00\00\00" - "\06\0a\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\80\80\80\80\00" ;; i32.const 0 - "\0b" ;; end -) -(module binary - "\00asm" "\01\00\00\00" - "\06\0a\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\ff\ff\ff\ff\7f" ;; i32.const -1 - "\0b" ;; end -) - -(module binary - "\00asm" "\01\00\00\00" - "\06\07\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\80\00" ;; i64.const 0 with unused bits set - "\0b" ;; end -) -(module binary - "\00asm" "\01\00\00\00" - "\06\07\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\ff\7f" ;; i64.const -1 with unused bits unset - "\0b" ;; end -) -(module binary - "\00asm" "\01\00\00\00" - "\06\0f\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\80\80\80\80\80\80\80\80\80\00" ;; i64.const 0 with unused bits set - "\0b" ;; end -) -(module binary - "\00asm" "\01\00\00\00" - "\06\0f\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\ff\ff\ff\ff\ff\ff\ff\ff\ff\7f" ;; i64.const -1 with unused bits unset - "\0b" ;; end -) - -(module binary - "\00asm" "\01\00\00\00" - "\05\03\01" ;; Memory section with 1 entry - "\00\00" ;; no max, minimum 0 - "\0b\06\01" ;; Data section with 1 entry - "\00" ;; Memory index 0 - "\41\00\0b\00" ;; (i32.const 0) with contents "" -) - -(module binary - "\00asm" "\01\00\00\00" - "\04\04\01" ;; Table section with 1 entry - "\70\00\00" ;; no max, minimum 0, funcref - "\09\06\01" ;; Element section with 1 entry - "\00" ;; Table index 0 - "\41\00\0b\00" ;; (i32.const 0) with no elements -) - ;; Data segment tags and memory index can have non-minimal length (module binary "\00asm" "\01\00\00\00" @@ -218,201 +129,6 @@ "integer representation too long" ) -;; Unsigned LEB128 must not be overlong -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\05\08\01" ;; Memory section with 1 entry - "\00\82\80\80\80\80\00" ;; no max, minimum 2 with one byte too many - ) - "integer representation too long" -) - -;; Signed LEB128 must not be overlong -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0b\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\80\80\80\80\80\00" ;; i32.const 0 with one byte too many - "\0b" ;; end - ) - "integer representation too long" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0b\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\ff\ff\ff\ff\ff\7f" ;; i32.const -1 with one byte too many - "\0b" ;; end - ) - "integer representation too long" -) - -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\10\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\80\80\80\80\80\80\80\80\80\80\00" ;; i64.const 0 with one byte too many - "\0b" ;; end - ) - "integer representation too long" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\10\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\ff\ff\ff\ff\ff\ff\ff\ff\ff\ff\7f" ;; i64.const -1 with one byte too many - "\0b" ;; end - ) - "integer representation too long" -) - -;; Unsigned LEB128s zero-extend -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\05\07\01" ;; Memory section with 1 entry - "\00\82\80\80\80\70" ;; no max, minimum 2 with unused bits set - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\05\07\01" ;; Memory section with 1 entry - "\00\82\80\80\80\40" ;; no max, minimum 2 with some unused bits set - ) - "integer too large" -) - -;; Signed LEB128s sign-extend -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0a\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\80\80\80\80\70" ;; i32.const 0 with unused bits set - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0a\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\ff\ff\ff\ff\0f" ;; i32.const -1 with unused bits unset - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0a\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\80\80\80\80\1f" ;; i32.const 0 with some unused bits set - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0a\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\ff\ff\ff\ff\4f" ;; i32.const -1 with some unused bits unset - "\0b" ;; end - ) - "integer too large" -) - -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0f\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\80\80\80\80\80\80\80\80\80\7e" ;; i64.const 0 with unused bits set - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0f\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\ff\ff\ff\ff\ff\ff\ff\ff\ff\01" ;; i64.const -1 with unused bits unset - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0f\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\80\80\80\80\80\80\80\80\80\02" ;; i64.const 0 with some unused bits set - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0f\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\ff\ff\ff\ff\ff\ff\ff\ff\ff\41" ;; i64.const -1 with some unused bits unset - "\0b" ;; end - ) - "integer too large" -) - -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0f\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\80\80\80\80\80\80\80\80\80\7e" ;; i64.const 0 with unused bits set - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0f\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\ff\ff\ff\ff\ff\ff\ff\ff\ff\01" ;; i64.const -1 with unused bits unset - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0f\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\80\80\80\80\80\80\80\80\80\02" ;; i64.const 0 with some unused bits set - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0f\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\ff\ff\ff\ff\ff\ff\ff\ff\ff\41" ;; i64.const -1 with some unused bits unset - "\0b" ;; end - ) - "integer too large" -) - ;; Function with missing end marker (between two functions) (assert_malformed (module binary @@ -483,395 +199,6 @@ "illegal opcode" ) -;; Unsigned LEB128 must not be overlong -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\05\08\01" ;; Memory section with 1 entry - "\00\82\80\80\80\80\00" ;; no max, minimum 2 with one byte too many - ) - "integer representation too long" -) -;; The memory offset will be decoded as u64 in the memory64 proposal. -;; TODO: Re-enable this test as assert_trap test in the memory64 repo. -;; (assert_malformed -;; (module binary -;; "\00asm" "\01\00\00\00" -;; "\01\04\01\60\00\00" ;; Type section -;; "\03\02\01\00" ;; Function section -;; "\05\03\01\00\01" ;; Memory section -;; "\0a\11\01" ;; Code section -;; ;; function 0 -;; "\0f\01\01" ;; local type count -;; "\7f" ;; i32 -;; "\41\00" ;; i32.const 0 -;; "\28" ;; i32.load -;; "\02" ;; alignment 2 -;; "\82\80\80\80\80\00" ;; offset 2 with one byte too many -;; "\1a" ;; drop -;; "\0b" ;; end -;; ) -;; "integer representation too long" -;; ) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\11\01" ;; Code section - ;; function 0 - "\0f\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\28" ;; i32.load - "\82\80\80\80\80\00" ;; alignment 2 with one byte too many - "\00" ;; offset 0 - "\1a" ;; drop - "\0b" ;; end - ) - "integer representation too long" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\12\01" ;; Code section - ;; function 0 - "\10\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\41\03" ;; i32.const 3 - "\36" ;; i32.store - "\82\80\80\80\80\00" ;; alignment 2 with one byte too many - "\03" ;; offset 3 - "\0b" ;; end - ) - "integer representation too long" -) -;; The memory offset will be decoded as u64 in the memory64 proposal. -;; TODO: Re-enable this test as assert_trap test in the memory64 repo. -;; (assert_malformed -;; (module binary -;; "\00asm" "\01\00\00\00" -;; "\01\04\01\60\00\00" ;; Type section -;; "\03\02\01\00" ;; Function section -;; "\05\03\01\00\01" ;; Memory section -;; "\0a\12\01" ;; Code section -;; ;; function 0 -;; "\10\01\01" ;; local type count -;; "\7f" ;; i32 -;; "\41\00" ;; i32.const 0 -;; "\41\03" ;; i32.const 3 -;; "\36" ;; i32.store -;; "\02" ;; alignment 2 -;; "\82\80\80\80\80\00" ;; offset 2 with one byte too many -;; "\0b" ;; end -;; ) -;; "integer representation too long" -;; ) - -;; Signed LEB128 must not be overlong -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0b\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\80\80\80\80\80\00" ;; i32.const 0 with one byte too many - "\0b" ;; end - ) - "integer representation too long" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0b\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\ff\ff\ff\ff\ff\7f" ;; i32.const -1 with one byte too many - "\0b" ;; end - ) - "integer representation too long" -) - -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\10\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\80\80\80\80\80\80\80\80\80\80\00" ;; i64.const 0 with one byte too many - "\0b" ;; end - ) - "integer representation too long" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\10\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\ff\ff\ff\ff\ff\ff\ff\ff\ff\ff\7f" ;; i64.const -1 with one byte too many - "\0b" ;; end - ) - "integer representation too long" -) - -;; Unsigned LEB128s zero-extend -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\05\07\01" ;; Memory section with 1 entry - "\00\82\80\80\80\70" ;; no max, minimum 2 with unused bits set - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\05\07\01" ;; Memory section with 1 entry - "\00\82\80\80\80\40" ;; no max, minimum 2 with some unused bits set - ) - "integer too large" -) -;; The memory offset will be decoded as u64 in the memory64 proposal. -;; TODO: Re-enable this test as assert_trap test in the memory64 repo. -;; (assert_malformed -;; (module binary -;; "\00asm" "\01\00\00\00" -;; "\01\04\01\60\00\00" ;; Type section -;; "\03\02\01\00" ;; Function section -;; "\05\03\01\00\01" ;; Memory section -;; "\0a\10\01" ;; Code section -;; ;; function 0 -;; "\0e\01\01" ;; local type count -;; "\7f" ;; i32 -;; "\41\00" ;; i32.const 0 -;; "\28" ;; i32.load -;; "\02" ;; alignment 2 -;; "\82\80\80\80\10" ;; offset 2 with unused bits set -;; "\1a" ;; drop -;; "\0b" ;; end -;; ) -;; "integer too large" -;; ) -;; (assert_malformed -;; (module binary -;; "\00asm" "\01\00\00\00" -;; "\01\04\01\60\00\00" ;; Type section -;; "\03\02\01\00" ;; Function section -;; "\05\03\01\00\01" ;; Memory section -;; "\0a\10\01" ;; Code section -;; ;; function 0 -;; "\0e\01\01" ;; local type count -;; "\7f" ;; i32 -;; "\41\00" ;; i32.const 0 -;; "\28" ;; i32.load -;; "\02" ;; alignment 2 -;; "\82\80\80\80\40" ;; offset 2 with some unused bits set -;; "\1a" ;; drop -;; "\0b" ;; end -;; ) -;; "integer too large" -;; ) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\10\01" ;; Code section - "\0e\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\28" ;; i32.load - "\82\80\80\80\10" ;; alignment 2 with unused bits set - "\00" ;; offset 0 - "\1a" ;; drop - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\10\01" ;; Code section - ;; function 0 - "\0e\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\28" ;; i32.load - "\82\80\80\80\40" ;; alignment 2 with some unused bits set - "\00" ;; offset 0 - "\1a" ;; drop - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\11\01" ;; Code section - ;; function 0 - "\0f\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\41\03" ;; i32.const 3 - "\36" ;; i32.store - "\82\80\80\80\10" ;; alignment 2 with unused bits set - "\03" ;; offset 3 - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\11\01" ;; Code section - ;; function 0 - "\0f\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\41\03" ;; i32.const 3 - "\36" ;; i32.store - "\82\80\80\80\40" ;; alignment 2 with some unused bits set - "\03" ;; offset 3 - "\0b" ;; end - ) - "integer too large" -) -;; The memory offset will be decoded as u64 in the memory64 proposal. -;; TODO: Re-enable this test as assert_trap test in the memory64 repo. -;; (assert_malformed -;; (module binary -;; "\00asm" "\01\00\00\00" -;; "\01\04\01\60\00\00" ;; Type section -;; "\03\02\01\00" ;; Function section -;; "\05\03\01\00\01" ;; Memory section -;; "\0a\11\01" ;; Code section -;; ;; function 0 -;; "\0f\01\01" ;; local type count -;; "\7f" ;; i32 -;; "\41\00" ;; i32.const 0 -;; "\41\03" ;; i32.const 3 -;; "\36" ;; i32.store -;; "\02" ;; alignment 2 -;; "\82\80\80\80\10" ;; offset 2 with unused bits set -;; "\0b" ;; end -;; ) -;; "integer too large" -;; ) -;; (assert_malformed -;; (module binary -;; "\00asm" "\01\00\00\00" -;; "\01\04\01\60\00\00" ;; Type section -;; "\03\02\01\00" ;; Function section -;; "\05\03\01\00\01" ;; Memory section -;; "\0a\11\01" ;; Code section -;; ;; function 0 -;; "\0f\01\01" ;; local type count -;; "\7f" ;; i32 -;; "\41\00" ;; i32.const 0 -;; "\41\03" ;; i32.const 3 -;; "\36" ;; i32.store -;; "\02" ;; alignment 2 -;; "\82\80\80\80\40" ;; offset 2 with some unused bits set -;; "\0b" ;; end -;; ) -;; "integer too large" -;; ) - -;; Signed LEB128s sign-extend -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0a\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\80\80\80\80\70" ;; i32.const 0 with unused bits set - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0a\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\ff\ff\ff\ff\0f" ;; i32.const -1 with unused bits unset - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0a\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\80\80\80\80\1f" ;; i32.const 0 with some unused bits set - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0a\01" ;; Global section with 1 entry - "\7f\00" ;; i32, immutable - "\41\ff\ff\ff\ff\4f" ;; i32.const -1 with some unused bits unset - "\0b" ;; end - ) - "integer too large" -) - -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0f\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\80\80\80\80\80\80\80\80\80\7e" ;; i64.const 0 with unused bits set - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0f\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\ff\ff\ff\ff\ff\ff\ff\ff\ff\01" ;; i64.const -1 with unused bits unset - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0f\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\80\80\80\80\80\80\80\80\80\02" ;; i64.const 0 with some unused bits set - "\0b" ;; end - ) - "integer too large" -) -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\06\0f\01" ;; Global section with 1 entry - "\7e\00" ;; i64, immutable - "\42\ff\ff\ff\ff\ff\ff\ff\ff\ff\41" ;; i64.const -1 with some unused bits unset - "\0b" ;; end - ) - "integer too large" -) - ;; memory.grow reserved byte equal to zero. (assert_malformed (module binary From 86b6a183594d770ab37e868e1d755495d44cf243 Mon Sep 17 00:00:00 2001 From: Clemens Backes Date: Wed, 10 May 2023 18:14:50 +0200 Subject: [PATCH 06/12] Make binary-leb128 test memory64-ready (#1650) This merges part of WebAssembly/memory64#14 to make the tests fail both before and after memory64. This allows engines to enable memory64 without failing spec tests. --- test/core/binary-leb128.wast | 165 ++++++++++++++++++----------------- 1 file changed, 84 insertions(+), 81 deletions(-) diff --git a/test/core/binary-leb128.wast b/test/core/binary-leb128.wast index 1b642261..e4a67d6b 100644 --- a/test/core/binary-leb128.wast +++ b/test/core/binary-leb128.wast @@ -404,19 +404,19 @@ (assert_malformed (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\11\01" ;; Code section + "\01\04\01\60\00\00" ;; Type section + "\03\02\01\00" ;; Function section + "\05\03\01\00\01" ;; Memory section + "\0a\11\01" ;; Code section ;; function 0 - "\0f\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\28" ;; i32.load - "\02" ;; alignment 2 - "\82\80\80\80\80\00" ;; offset 2 with one byte too many - "\1a" ;; drop - "\0b" ;; end + "\0f\01\01" ;; local type count + "\7f" ;; i32 + "\41\00" ;; i32.const 0 + "\28" ;; i32.load + "\02" ;; alignment 2 + "\82\80\80\80\80\80\80\80\80\80\00" ;; offset 2 with one byte too many + "\1a" ;; drop + "\0b" ;; end ) "integer representation too long" ) @@ -461,19 +461,19 @@ (assert_malformed (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\12\01" ;; Code section + "\01\04\01\60\00\00" ;; Type section + "\03\02\01\00" ;; Function section + "\05\03\01\00\01" ;; Memory section + "\0a\12\01" ;; Code section ;; function 0 - "\10\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\41\03" ;; i32.const 3 - "\36" ;; i32.store - "\02" ;; alignment 2 - "\82\80\80\80\80\00" ;; offset 2 with one byte too many - "\0b" ;; end + "\10\01\01" ;; local type count + "\7f" ;; i32 + "\41\00" ;; i32.const 0 + "\41\03" ;; i32.const 3 + "\36" ;; i32.store + "\02" ;; alignment 2 + "\82\80\80\80\80\80\80\80\80\80\00" ;; offset 2 with one byte too many + "\0b" ;; end ) "integer representation too long" ) @@ -730,40 +730,42 @@ (assert_malformed (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\10\01" ;; Code section + "\01\04\01\60\00\00" ;; Type section + "\03\02\01\00" ;; Function section + "\05\03\01\00\01" ;; Memory section + "\0a\10\01" ;; Code section ;; function 0 - "\0e\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\28" ;; i32.load - "\02" ;; alignment 2 - "\82\80\80\80\10" ;; offset 2 with unused bits set - "\1a" ;; drop - "\0b" ;; end - ) - "integer too large" + "\0e\01\01" ;; local type count + "\7f" ;; i32 + "\41\00" ;; i32.const 0 + "\28" ;; i32.load + "\02" ;; alignment 2 + "\82\80\80\80\80\80\80\80\80\10" ;; offset 2 with unused bits set + "\1a" ;; drop + "\0b" ;; end + ) + ;; TODO: This changes to "integer too large" with memory64. + "integer representation too long" ) (assert_malformed (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\10\01" ;; Code section + "\01\04\01\60\00\00" ;; Type section + "\03\02\01\00" ;; Function section + "\05\03\01\00\01" ;; Memory section + "\0a\10\01" ;; Code section ;; function 0 - "\0e\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\28" ;; i32.load - "\02" ;; alignment 2 - "\82\80\80\80\40" ;; offset 2 with some unused bits set - "\1a" ;; drop - "\0b" ;; end - ) - "integer too large" + "\0e\01\01" ;; local type count + "\7f" ;; i32 + "\41\00" ;; i32.const 0 + "\28" ;; i32.load + "\02" ;; alignment 2 + "\82\80\80\80\80\80\80\80\80\40" ;; offset 2 with some unused bits set + "\1a" ;; drop + "\0b" ;; end + ) + ;; TODO: This changes to "integer too large" with memory64. + "integer representation too long" ) (assert_malformed (module binary @@ -843,41 +845,42 @@ (assert_malformed (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\11\01" ;; Code section + "\01\04\01\60\00\00" ;; Type section + "\03\02\01\00" ;; Function section + "\05\03\01\00\01" ;; Memory section + "\0a\11\01" ;; Code section ;; function 0 - "\0f\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\41\03" ;; i32.const 3 - "\36" ;; i32.store - "\02" ;; alignment 2 - "\82\80\80\80\10" ;; offset 2 with unused bits set - "\0b" ;; end - ) - "integer too large" + "\0f\01\01" ;; local type count + "\7f" ;; i32 + "\41\00" ;; i32.const 0 + "\41\03" ;; i32.const 3 + "\36" ;; i32.store + "\02" ;; alignment 2 + "\82\80\80\80\80\80\80\80\80\10" ;; offset 2 with unused bits set + "\0b" ;; end + ) + ;; TODO: This changes to "integer too large" with memory64. + "integer representation too long" ) (assert_malformed (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section - "\03\02\01\00" ;; Function section - "\05\03\01\00\01" ;; Memory section - "\0a\11\01" ;; Code section - + "\01\04\01\60\00\00" ;; Type section + "\03\02\01\00" ;; Function section + "\05\03\01\00\01" ;; Memory section + "\0a\11\01" ;; Code section ;; function 0 - "\0f\01\01" ;; local type count - "\7f" ;; i32 - "\41\00" ;; i32.const 0 - "\41\03" ;; i32.const 3 - "\36" ;; i32.store - "\02" ;; alignment 2 - "\82\80\80\80\40" ;; offset 2 with some unused bits set - "\0b" ;; end - ) - "integer too large" + "\0f\01\01" ;; local type count + "\7f" ;; i32 + "\41\00" ;; i32.const 0 + "\41\03" ;; i32.const 3 + "\36" ;; i32.store + "\02" ;; alignment 2 + "\82\80\80\80\80\80\80\80\80\40" ;; offset 2 with some unused bits set + "\0b" ;; end + ) + ;; TODO: This changes to "integer too large" with memory64. + "integer representation too long" ) ;; Signed LEB128s sign-extend From fe355113fdc439f3cc06b720089168fc853247e5 Mon Sep 17 00:00:00 2001 From: Clemens Backes Date: Wed, 10 May 2023 19:40:24 +0200 Subject: [PATCH 07/12] Move more LEB128 tests to binary-leb128 (#1651) Tests for LEB128 should be in the separate `binary-leb128.wast` test file. --- test/core/binary-leb128.wast | 79 +++++++++++++++++++++++++++++++++++- test/core/binary.wast | 78 ----------------------------------- 2 files changed, 78 insertions(+), 79 deletions(-) diff --git a/test/core/binary-leb128.wast b/test/core/binary-leb128.wast index e4a67d6b..335496f0 100644 --- a/test/core/binary-leb128.wast +++ b/test/core/binary-leb128.wast @@ -966,7 +966,6 @@ "integer too large" ) - (module binary "\00asm" "\01\00\00\00" "\01\04\01" ;; type section @@ -1003,3 +1002,81 @@ ) "integer representation too long" ) + +;; Data segment tags and memory index can have non-minimal length +(module binary + "\00asm" "\01\00\00\00" + "\05\03\01" ;; Memory section with 1 entry + "\00\00" ;; no max, minimum 0 + "\0b\07\01" ;; Data section with 1 entry + "\80\00" ;; Active segment, encoded with 2 bytes + "\41\00\0b\00" ;; (i32.const 0) with contents "" +) +(module binary + "\00asm" "\01\00\00\00" + "\05\03\01" ;; Memory section with 1 entry + "\00\00" ;; no max, minimum 0 + "\0b\08\01" ;; Data section with 1 entry + "\82\00" ;; Active segment, encoded with 2 bytes + "\00" ;; explicit memory index + "\41\00\0b\00" ;; (i32.const 0) with contents "" +) +(module binary + "\00asm" "\01\00\00\00" + "\05\03\01" ;; Memory section with 1 entry + "\00\00" ;; no max, minimum 0 + "\0b\09\01" ;; Data section with 1 entry + "\82\00" ;; Active segment, encoded with 2 bytes + "\80\00" ;; explicit memory index, encoded with 2 bytes + "\41\00\0b\00" ;; (i32.const 0) with contents "" +) + +;; Element segment tags and table index can have non-minimal length +(module binary + "\00asm" "\01\00\00\00" + "\04\04\01" ;; Table section with 1 entry + "\70\00\00" ;; no max, minimum 0, funcref + "\09\07\01" ;; Element section with 1 entry + "\80\00" ;; Active segment + "\41\00\0b\00" ;; (i32.const 0) with no elements +) +(module binary + "\00asm" "\01\00\00\00" + "\04\04\01" ;; Table section with 1 entry + "\70\00\00" ;; no max, minimum 0, funcref + "\09\09\01" ;; Element section with 1 entry + "\02" ;; Active segment + "\80\00" ;; explicit table index, encoded with 2 bytes + "\41\00\0b\00\00" ;; (i32.const 0) with no elements +) +(module binary + "\00asm" "\01\00\00\00" + "\04\04\01" ;; Table section with 1 entry + "\70\00\00" ;; no max, minimum 0, funcref + "\09\09\01" ;; Element section with 1 entry + "\82\00" ;; Active segment, encoded with 2 bytes + "\00" ;; explicit table index + "\41\00\0b\00\00" ;; (i32.const 0) with no elements +) +(module binary + "\00asm" "\01\00\00\00" + "\04\04\01" ;; Table section with 1 entry + "\70\00\00" ;; no max, minimum 0, funcref + "\09\0a\01" ;; Element section with 1 entry + "\82\00" ;; Active segment, encoded with 2 bytes + "\80\00" ;; explicit table index, encoded with 2 bytes + "\41\00\0b\00\00" ;; (i32.const 0) with no elements +) + +;; Type section with signed LEB128 encoded type +(assert_malformed + (module binary + "\00asm" "\01\00\00\00" + "\01" ;; Type section id + "\05" ;; Type section length + "\01" ;; Types vector length + "\e0\7f" ;; Malformed functype, -0x20 in signed LEB128 encoding + "\00\00" + ) + "integer representation too long" +) diff --git a/test/core/binary.wast b/test/core/binary.wast index 329b8a5a..c777bebb 100644 --- a/test/core/binary.wast +++ b/test/core/binary.wast @@ -51,84 +51,6 @@ (assert_malformed (module binary "\00asm" "\01\00\00\00" "\81\01\00\01\01\00") "malformed section id") (assert_malformed (module binary "\00asm" "\01\00\00\00" "\ff\01\00\01\01\00") "malformed section id") -;; Data segment tags and memory index can have non-minimal length -(module binary - "\00asm" "\01\00\00\00" - "\05\03\01" ;; Memory section with 1 entry - "\00\00" ;; no max, minimum 0 - "\0b\07\01" ;; Data section with 1 entry - "\80\00" ;; Active segment, encoded with 2 bytes - "\41\00\0b\00" ;; (i32.const 0) with contents "" -) -(module binary - "\00asm" "\01\00\00\00" - "\05\03\01" ;; Memory section with 1 entry - "\00\00" ;; no max, minimum 0 - "\0b\08\01" ;; Data section with 1 entry - "\82\00" ;; Active segment, encoded with 2 bytes - "\00" ;; explicit memory index - "\41\00\0b\00" ;; (i32.const 0) with contents "" -) -(module binary - "\00asm" "\01\00\00\00" - "\05\03\01" ;; Memory section with 1 entry - "\00\00" ;; no max, minimum 0 - "\0b\09\01" ;; Data section with 1 entry - "\82\00" ;; Active segment, encoded with 2 bytes - "\80\00" ;; explicit memory index, encoded with 2 bytes - "\41\00\0b\00" ;; (i32.const 0) with contents "" -) - -;; Element segment tags and table index can have non-minimal length -(module binary - "\00asm" "\01\00\00\00" - "\04\04\01" ;; Table section with 1 entry - "\70\00\00" ;; no max, minimum 0, funcref - "\09\07\01" ;; Element section with 1 entry - "\80\00" ;; Active segment - "\41\00\0b\00" ;; (i32.const 0) with no elements -) -(module binary - "\00asm" "\01\00\00\00" - "\04\04\01" ;; Table section with 1 entry - "\70\00\00" ;; no max, minimum 0, funcref - "\09\09\01" ;; Element section with 1 entry - "\02" ;; Active segment - "\80\00" ;; explicit table index, encoded with 2 bytes - "\41\00\0b\00\00" ;; (i32.const 0) with no elements -) -(module binary - "\00asm" "\01\00\00\00" - "\04\04\01" ;; Table section with 1 entry - "\70\00\00" ;; no max, minimum 0, funcref - "\09\09\01" ;; Element section with 1 entry - "\82\00" ;; Active segment, encoded with 2 bytes - "\00" ;; explicit table index - "\41\00\0b\00\00" ;; (i32.const 0) with no elements -) -(module binary - "\00asm" "\01\00\00\00" - "\04\04\01" ;; Table section with 1 entry - "\70\00\00" ;; no max, minimum 0, funcref - "\09\0a\01" ;; Element section with 1 entry - "\82\00" ;; Active segment, encoded with 2 bytes - "\80\00" ;; explicit table index, encoded with 2 bytes - "\41\00\0b\00\00" ;; (i32.const 0) with no elements -) - -;; Type section with signed LEB128 encoded type -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\01" ;; Type section id - "\05" ;; Type section length - "\01" ;; Types vector length - "\e0\7f" ;; Malformed functype, -0x20 in signed LEB128 encoding - "\00\00" - ) - "integer representation too long" -) - ;; Function with missing end marker (between two functions) (assert_malformed (module binary From 2e8912e88a3118a46b90e8ccb659e24b4e8f3c23 Mon Sep 17 00:00:00 2001 From: Clemens Backes Date: Fri, 12 May 2023 12:20:37 +0200 Subject: [PATCH 08/12] Allow test for module size limit to fail (#1653) * Allow test for module size limit to fail Allocating a 1GB Uint8Array can fail. In particular, it will always fail on 32-bit systems in V8, where the maximum size of a TypedArray is 2^30-1, thus 1 byte too little. --- test/js-api/limits.any.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/js-api/limits.any.js b/test/js-api/limits.any.js index 91f058d6..d913c6c7 100644 --- a/test/js-api/limits.any.js +++ b/test/js-api/limits.any.js @@ -250,7 +250,16 @@ function testModuleSizeLimit(size, expectPass) { // Define a WebAssembly module that consists of a single custom section which // has an empty name. The module size will be `size`. - const buffer = new Uint8Array(size); + let buffer; + try { + buffer = new Uint8Array(size); + } catch (e) { + if (e instanceof RangeError) { + // Allocation of a big TypedArray may fail. + return; + } + throw e; + } const header = [ kWasmH0, kWasmH1, kWasmH2, kWasmH3, // magic word kWasmV0, kWasmV1, kWasmV2, kWasmV3, // version From 083f24cad6f181c7e393ab840e21c0f001cf4615 Mon Sep 17 00:00:00 2001 From: Phosra Date: Mon, 29 May 2023 23:30:51 -0700 Subject: [PATCH 09/12] [spec] Fix table_alloc signature (#1658) --- document/core/appendix/embedding.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document/core/appendix/embedding.rst b/document/core/appendix/embedding.rst index 27aac4b3..96fa6b2f 100644 --- a/document/core/appendix/embedding.rst +++ b/document/core/appendix/embedding.rst @@ -323,7 +323,7 @@ Tables .. _embed-table-alloc: -:math:`\F{table\_alloc}(\store, \tabletype) : (\store, \tableaddr, \reff)` +:math:`\F{table\_alloc}(\store, \tabletype, \reff) : (\store, \tableaddr)` .......................................................................... 1. Pre-condition: :math:`\tabletype` is :ref:`valid `. From 933d2dd95be2357bd936d4e400e853f8ec728ebd Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Tue, 30 May 2023 11:09:55 +0200 Subject: [PATCH 10/12] [interpreter] Tweak parser --- interpreter/text/parser.mly | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/interpreter/text/parser.mly b/interpreter/text/parser.mly index 7489acf7..e29be3ae 100644 --- a/interpreter/text/parser.mly +++ b/interpreter/text/parser.mly @@ -732,11 +732,11 @@ elem_expr_list : elem_var_list : | var_list { let f = function {at; _} as x -> [ref_func x @@ at] @@ at in - fun c lookup -> List.map f ($1 c lookup) } + fun c -> List.map f ($1 c func) } elem_list : | elem_kind elem_var_list - { ($1, fun c -> $2 c func) } + { ($1, fun c -> $2 c) } | ref_type elem_expr_list { ($1, fun c -> $2 c) } @@ -768,7 +768,7 @@ elem : { let at = at () in fun c -> ignore ($3 c anon_elem bind_elem); fun () -> - { etype = FuncRefType; einit = $5 c func; + { etype = FuncRefType; einit = $5 c; emode = Active {index = 0l @@ at; offset = $4 c} @@ at } @@ at } table : @@ -788,19 +788,19 @@ table_fields : | inline_export table_fields /* Sugar */ { fun c x at -> let tabs, elems, ims, exs = $2 c x at in tabs, elems, ims, $1 (TableExport x) c :: exs } - | ref_type LPAR ELEM elem_var_list RPAR /* Sugar */ + | ref_type LPAR ELEM elem_expr elem_expr_list RPAR /* Sugar */ { fun c x at -> let offset = [i32_const (0l @@ at) @@ at] @@ at in - let einit = $4 c func in + let einit = $4 c :: $5 c in let size = Lib.List32.length einit in let emode = Active {index = x; offset} @@ at in [{ttype = TableType ({min = size; max = Some size}, $1)} @@ at], - [{etype = FuncRefType; einit; emode} @@ at], + [{etype = $1; einit; emode} @@ at], [], [] } - | ref_type LPAR ELEM elem_expr elem_expr_list RPAR /* Sugar */ + | ref_type LPAR ELEM elem_var_list RPAR /* Sugar */ { fun c x at -> let offset = [i32_const (0l @@ at) @@ at] @@ at in - let einit = (fun c -> $4 c :: $5 c) c in + let einit = $4 c in let size = Lib.List32.length einit in let emode = Active {index = x; offset} @@ at in [{ttype = TableType ({min = size; max = Some size}, $1)} @@ at], From b55d740054915ffc9089e709c99f3319ae6baabc Mon Sep 17 00:00:00 2001 From: Tom Stuart Date: Tue, 30 May 2023 10:57:59 +0100 Subject: [PATCH 11/12] [spec] Include reftype in inline element segment abbreviations (#1657) --- document/core/text/modules.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/document/core/text/modules.rst b/document/core/text/modules.rst index c3407732..5aab9b32 100644 --- a/document/core/text/modules.rst +++ b/document/core/text/modules.rst @@ -292,7 +292,7 @@ An :ref:`element segment ` can be given inline with a table definitio \production{module field} & \text{(}~\text{table}~~\Tid^?~~\Treftype~~\text{(}~\text{elem}~~\expr^n{:}\Tvec(\Telemexpr)~\text{)}~\text{)} \quad\equiv \\ & \qquad \text{(}~\text{table}~~\Tid'~~n~~n~~\Treftype~\text{)} \\ & \qquad - \text{(}~\text{elem}~~\text{(}~\text{table}~~\Tid'~\text{)}~~\text{(}~\text{i32.const}~~\text{0}~\text{)}~~\Tvec(\Telemexpr)~\text{)} + \text{(}~\text{elem}~~\text{(}~\text{table}~~\Tid'~\text{)}~~\text{(}~\text{i32.const}~~\text{0}~\text{)}~~\Treftype~~\Tvec(\Telemexpr)~\text{)} \\ & \qquad\qquad (\iff \Tid^? \neq \epsilon \wedge \Tid' = \Tid^? \vee \Tid^? = \epsilon \wedge \Tid' \idfresh) \\ \end{array} @@ -302,7 +302,7 @@ An :ref:`element segment ` can be given inline with a table definitio \production{module field} & \text{(}~\text{table}~~\Tid^?~~\Treftype~~\text{(}~\text{elem}~~x^n{:}\Tvec(\Tfuncidx)~\text{)}~\text{)} \quad\equiv \\ & \qquad \text{(}~\text{table}~~\Tid'~~n~~n~~\Treftype~\text{)} \\ & \qquad - \text{(}~\text{elem}~~\text{(}~\text{table}~~\Tid'~\text{)}~~\text{(}~\text{i32.const}~~\text{0}~\text{)}~~\Tvec(\Tfuncidx)~\text{)} + \text{(}~\text{elem}~~\text{(}~\text{table}~~\Tid'~\text{)}~~\text{(}~\text{i32.const}~~\text{0}~\text{)}~~\text{func}~~\Tvec(\Tfuncidx)~\text{)} \\ & \qquad\qquad (\iff \Tid^? \neq \epsilon \wedge \Tid' = \Tid^? \vee \Tid^? = \epsilon \wedge \Tid' \idfresh) \\ \end{array} From e19508ade330025158cb2755fa4bbd1b53990a1b Mon Sep 17 00:00:00 2001 From: Reuben Dunnington Date: Mon, 5 Jun 2023 22:47:11 -0700 Subject: [PATCH 12/12] [spec] Fix copypaste error for V128.Load*_Zero instructions in index (#1662) --- document/core/appendix/index-instructions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/document/core/appendix/index-instructions.py b/document/core/appendix/index-instructions.py index 2503a7ab..c3ffc2a3 100755 --- a/document/core/appendix/index-instructions.py +++ b/document/core/appendix/index-instructions.py @@ -431,8 +431,8 @@ def Instruction(name, opcode, type=None, validation=None, execution=None, operat Instruction(r'\V128.\STORE\K{16\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{59}', r'[\I32~\V128] \to []', r'valid-store-lane', r'exec-store-lane'), Instruction(r'\V128.\STORE\K{32\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{5A}', r'[\I32~\V128] \to []', r'valid-store-lane', r'exec-store-lane'), Instruction(r'\V128.\STORE\K{64\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{5B}', r'[\I32~\V128] \to []', r'valid-store-lane', r'exec-store-lane'), - Instruction(r'\V128.\LOAD\K{32\_zero}~\memarg~\laneidx', r'\hex{FD}~~\hex{5C}', r'[\I32] \to [\V128]', r'valid-load-zero', r'exec-load-zero'), - Instruction(r'\V128.\LOAD\K{64\_zero}~\memarg~\laneidx', r'\hex{FD}~~\hex{5D}', r'[\I32] \to [\V128]', r'valid-load-zero', r'exec-load-zero'), + Instruction(r'\V128.\LOAD\K{32\_zero}~\memarg', r'\hex{FD}~~\hex{5C}', r'[\I32] \to [\V128]', r'valid-load-zero', r'exec-load-zero'), + Instruction(r'\V128.\LOAD\K{64\_zero}~\memarg', r'\hex{FD}~~\hex{5D}', r'[\I32] \to [\V128]', r'valid-load-zero', r'exec-load-zero'), Instruction(r'\F32X4.\VDEMOTE\K{\_f64x2\_zero}', r'\hex{FD}~~\hex{5E}', r'[\V128] \to [\V128]', r'valid-vcvtop', r'exec-vcvtop', r'op-demote'), Instruction(r'\F64X2.\VPROMOTE\K{\_low\_f32x4}', r'\hex{FD}~~\hex{5F}', r'[\V128] \to [\V128]', r'valid-vcvtop', r'exec-vcvtop', r'op-promote'), Instruction(r'\I8X16.\VABS', r'\hex{FD}~~\hex{60}', r'[\V128] \to [\V128]', r'valid-vunop', r'exec-vunop', r'op-iabs'),