From 621d8c09e2433d5a7816bddb303aeb223868d7a6 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 30 Apr 2024 10:44:48 -0700 Subject: [PATCH 1/3] [test] Add `--failfast` flag to test runner (#1747) --- test/core/run.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/core/run.py b/test/core/run.py index 3ba97d1b9a..6500e6a6bb 100755 --- a/test/core/run.py +++ b/test/core/run.py @@ -19,6 +19,7 @@ parser.add_argument("--wasm", metavar="", default=os.path.join(interpDir, "wasm")) parser.add_argument("--js", metavar="") parser.add_argument("--generate-js-only", action='store_true') +parser.add_argument("--failfast", action='store_true') parser.add_argument("--out", metavar="", default=outputDir) parser.add_argument("file", nargs='*') arguments = parser.parse_args() @@ -117,4 +118,4 @@ def _runTestFile(self, inputPath): for fileName in inputFiles: testName = 'test ' + os.path.basename(fileName) setattr(RunTests, testName, lambda self, file=fileName: self._runTestFile(file)) - unittest.main() + unittest.main(failfast=arguments.failfast) From b4dd1800d83e1028b94b6bd62707473720302991 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Thu, 2 May 2024 09:46:47 -0700 Subject: [PATCH 2/3] [test] Use `node` over `spidermonkey` by default (#1748) --- test/meta/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/meta/Makefile b/test/meta/Makefile index 20e9adb2f5..05a42beb79 100644 --- a/test/meta/Makefile +++ b/test/meta/Makefile @@ -1,10 +1,10 @@ SHARED_MEM=false # SpiderMonkey shell -JSSHELL=~/mozilla-central/js/src/build-debug/dist/bin/js -e 'const WITH_SHARED_MEMORY=$(SHARED_MEM);' -f common.js +#JSSHELL=~/mozilla-central/js/src/build-debug/dist/bin/js -e 'const WITH_SHARED_MEMORY=$(SHARED_MEM);' -f common.js # Node.js -#JSSHELL=./noderun.sh $(SHARED_MEM) +JSSHELL=./noderun.sh $(SHARED_MEM) TARGETDIR=../core From 228549757b301c698c5588ec0d58b201b5777c92 Mon Sep 17 00:00:00 2001 From: Soni L Date: Wed, 8 May 2024 17:12:41 -0300 Subject: [PATCH 3/3] [test] Add tests for and fix alignment overflow (#1751) --- interpreter/binary/decode.ml | 2 +- test/core/align.wast | 117 +++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 1 deletion(-) diff --git a/interpreter/binary/decode.ml b/interpreter/binary/decode.ml index fa3a0ef9e5..43de4553b0 100644 --- a/interpreter/binary/decode.ml +++ b/interpreter/binary/decode.ml @@ -220,7 +220,7 @@ let zero s = expect 0x00 s "zero byte expected" let memop s = let align = u32 s in - require (I32.le_u align 32l) s (pos s - 1) "malformed memop flags"; + require (I32.lt_u align 32l) s (pos s - 1) "malformed memop flags"; let offset = u32 s in Int32.to_int align, offset diff --git a/test/core/align.wast b/test/core/align.wast index 93064649d3..7753df8deb 100644 --- a/test/core/align.wast +++ b/test/core/align.wast @@ -864,3 +864,120 @@ (assert_trap (invoke "store" (i32.const 65532) (i64.const -1)) "out of bounds memory access") ;; No memory was changed (assert_return (invoke "load" (i32.const 65532)) (i32.const 0)) + +;; Test invalid alignment values that may cause overflow when parsed. +;; These use the binary format, because it stores alignment as a base-2 exponent. + +;; Signed 32-bit overflow +(assert_invalid + (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 + "\05\03\01\00\01" ;; Memory section: 1 memory + "\0a\0a\01" ;; Code section: 1 function + + ;; function 0 + "\08\00" + "\41\00" ;; i32.const 0 + "\28\1f\00" ;; i32.load offset=0 align=2**31 + "\1a" ;; drop + "\0b" ;; end + ) + "alignment must not be larger than natural" +) + +;; Unsigned 32-bit overflow +(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 + "\05\03\01\00\01" ;; Memory section: 1 memory + "\0a\0a\01" ;; Code section: 1 function + + ;; function 0 + "\08\00" + "\41\00" ;; i32.const 0 + "\28\20\00" ;; i32.load offset=0 align=2**32 + "\1a" ;; drop + "\0b" ;; end + ) + "malformed memop flags" +) + +;; 32-bit out of range +(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 + "\05\03\01\00\01" ;; Memory section: 1 memory + "\0a\0a\01" ;; Code section: 1 function + + ;; function 0 + "\08\00" + "\41\00" ;; i32.const 0 + "\28\21\00" ;; i32.load offset=0 align=2**33 + "\1a" ;; drop + "\0b" ;; end + ) + "malformed memop flags" +) + +;; Signed 64-bit overflow +(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 + "\05\03\01\00\01" ;; Memory section: 1 memory + "\0a\0a\01" ;; Code section: 1 function + + ;; function 0 + "\08\00" + "\41\00" ;; i32.const 0 + "\28\3f\00" ;; i32.load offset=0 align=2**63 + "\1a" ;; drop + "\0b" ;; end + ) + "malformed memop flags" +) + +;; Unsigned 64-bit overflow +(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 + "\05\03\01\00\01" ;; Memory section: 1 memory + "\0a\0a\01" ;; Code section: 1 function + + ;; function 0 + "\08\00" + "\41\00" ;; i32.const 0 + "\28\40\00" ;; i32.load offset=0 align=2**64 + "\1a" ;; drop + "\0b" ;; end + ) + "malformed memop flags" +) + +;; 64-bit out of range +(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 + "\05\03\01\00\01" ;; Memory section: 1 memory + "\0a\0a\01" ;; Code section: 1 function + + ;; function 0 + "\08\00" + "\41\00" ;; i32.const 0 + "\28\41\00" ;; i32.load offset=0 align=2**65 + "\1a" ;; drop + "\0b" ;; end + ) + "malformed memop flags" +)