summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/asm2wasm.h3
-rw-r--r--src/ir/memory-utils.h4
-rw-r--r--src/tools/wasm-ctor-eval.cpp6
-rw-r--r--src/wasm/wasm-binary.cpp1
-rw-r--r--test/crash/expression-past-end-of-input.wasmbin0 -> 670 bytes
-rw-r--r--test/ctor-eval/imported-min.wast4
-rw-r--r--test/ctor-eval/imported-min.wast.out3
-rw-r--r--test/ctor-eval/imported.wast3
-rw-r--r--test/ctor-eval/imported.wast.out3
-rw-r--r--test/ctor-eval/imported3.wast2
-rw-r--r--test/ctor-eval/imported3.wast.out2
-rw-r--r--test/ctor-eval/unsafe_call.wast2
-rw-r--r--test/ctor-eval/unsafe_call.wast.out2
-rw-r--r--test/ctor-eval/unsafe_store.wast2
-rw-r--r--test/ctor-eval/unsafe_store.wast.out2
-rw-r--r--test/ctor-eval/unsafe_store2.wast2
-rw-r--r--test/ctor-eval/unsafe_store2.wast.out2
-rw-r--r--test/ctor-eval/unsafe_store3.wast2
-rw-r--r--test/ctor-eval/unsafe_store3.wast.out2
19 files changed, 20 insertions, 27 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index f6b6da43d..3ea9a3a1e 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -737,6 +737,9 @@ private:
void Asm2WasmBuilder::processAsm(Ref ast) {
assert(ast[0] == TOPLEVEL);
+ if (ast[1]->size() == 0) {
+ Fatal() << "empty input";
+ }
Ref asmFunction = ast[1][0];
assert(asmFunction[0] == DEFUN);
Ref body = asmFunction[3];
diff --git a/src/ir/memory-utils.h b/src/ir/memory-utils.h
index 920583f7d..5980a3218 100644
--- a/src/ir/memory-utils.h
+++ b/src/ir/memory-utils.h
@@ -36,8 +36,8 @@ namespace MemoryUtils {
}
for (auto& segment : memory.segments) {
auto* offset = segment.offset->dynCast<Const>();
- auto start = offset->value.getInteger();
- auto end = start + segment.data.size();
+ Index start = offset->value.getInteger();
+ Index end = start + segment.data.size();
if (end > data.size()) {
data.resize(end);
}
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp
index dee342255..e11454b04 100644
--- a/src/tools/wasm-ctor-eval.cpp
+++ b/src/tools/wasm-ctor-eval.cpp
@@ -31,6 +31,7 @@
#include "wasm-io.h"
#include "wasm-interpreter.h"
#include "wasm-builder.h"
+#include "wasm-validator.h"
#include "ir/memory-utils.h"
#include "ir/global-utils.h"
#include "ir/import-utils.h"
@@ -412,6 +413,11 @@ int main(int argc, const char* argv[]) {
}
}
+ if (!WasmValidator().validate(wasm)) {
+ WasmPrinter::printModule(&wasm);
+ Fatal() << "error in validating input";
+ }
+
// get list of ctors, and eval them
std::vector<std::string> ctors;
std::istringstream stream(ctorsString);
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index c60a3074a..5f4ace91b 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1341,6 +1341,7 @@ void WasmBinaryBuilder::processExpressions() {
if (pos == endOfFunction) {
throwError("Reached function end without seeing End opcode");
}
+ if (!more()) throwError("unexpected end of input");
auto peek = input[pos];
if (peek == BinaryConsts::End || peek == BinaryConsts::Else) {
if (debug) std::cerr << "== processExpressions finished with unreachable" << std::endl;
diff --git a/test/crash/expression-past-end-of-input.wasm b/test/crash/expression-past-end-of-input.wasm
new file mode 100644
index 000000000..4652a83a5
--- /dev/null
+++ b/test/crash/expression-past-end-of-input.wasm
Binary files differ
diff --git a/test/ctor-eval/imported-min.wast b/test/ctor-eval/imported-min.wast
index 8972a2ee1..80f2cbde2 100644
--- a/test/ctor-eval/imported-min.wast
+++ b/test/ctor-eval/imported-min.wast
@@ -4,8 +4,8 @@
;; stack imports are special
(import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32))
(import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32))
- ;; other imports must not be touched!
(import "env" "tempDoublePtr" (global $tempDoublePtr i32))
+ (global $tempDoublePtrMut (mut i32) (get_global $tempDoublePtr))
(export "test1" $test1)
(export "test2" $test2)
(export "test3" $test3)
@@ -39,7 +39,7 @@
(i32.store8 (i32.const 12) (i32.const 115))
)
(func $test2
- (set_global $tempDoublePtr (i32.const 1)) ;; bad!
+ (set_global $tempDoublePtrMut (i32.const 1)) ;; bad!
(i32.store8 (i32.const 13) (i32.const 115))
)
(func $test3
diff --git a/test/ctor-eval/imported-min.wast.out b/test/ctor-eval/imported-min.wast.out
index 3871caf2f..7b5c069ec 100644
--- a/test/ctor-eval/imported-min.wast.out
+++ b/test/ctor-eval/imported-min.wast.out
@@ -1,12 +1,13 @@
(module
(type $0 (func))
(import "env" "tempDoublePtr" (global $tempDoublePtr i32))
+ (global $tempDoublePtrMut (mut i32) (get_global $tempDoublePtr))
(memory $0 256 256)
(data (i32.const 10) "wasa waka waka waka waka")
(export "test2" (func $test2))
(export "test3" (func $test3))
(func $test2 (; 0 ;) (type $0)
- (set_global $tempDoublePtr
+ (set_global $tempDoublePtrMut
(i32.const 1)
)
(i32.store8
diff --git a/test/ctor-eval/imported.wast b/test/ctor-eval/imported.wast
index 3f065377d..982beacbe 100644
--- a/test/ctor-eval/imported.wast
+++ b/test/ctor-eval/imported.wast
@@ -6,6 +6,7 @@
(import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32))
;; other imports must not be touched!
(import "env" "tempDoublePtr" (global $tempDoublePtr i32))
+ (global $tempDoublePtrMut (mut i32) (get_global $tempDoublePtr))
(export "test1" $test1)
(export "test2" $test2)
(export "test3" $test3)
@@ -36,7 +37,7 @@
(i32.store8 (i32.const 12) (i32.const 115))
)
(func $test2
- (set_global $tempDoublePtr (i32.const 1)) ;; bad!
+ (set_global $tempDoublePtrMut (i32.const 1)) ;; bad!
(i32.store8 (i32.const 13) (i32.const 115))
)
(func $test3
diff --git a/test/ctor-eval/imported.wast.out b/test/ctor-eval/imported.wast.out
index 3871caf2f..7b5c069ec 100644
--- a/test/ctor-eval/imported.wast.out
+++ b/test/ctor-eval/imported.wast.out
@@ -1,12 +1,13 @@
(module
(type $0 (func))
(import "env" "tempDoublePtr" (global $tempDoublePtr i32))
+ (global $tempDoublePtrMut (mut i32) (get_global $tempDoublePtr))
(memory $0 256 256)
(data (i32.const 10) "wasa waka waka waka waka")
(export "test2" (func $test2))
(export "test3" (func $test3))
(func $test2 (; 0 ;) (type $0)
- (set_global $tempDoublePtr
+ (set_global $tempDoublePtrMut
(i32.const 1)
)
(i32.store8
diff --git a/test/ctor-eval/imported3.wast b/test/ctor-eval/imported3.wast
index b43ce3038..bd70a6f11 100644
--- a/test/ctor-eval/imported3.wast
+++ b/test/ctor-eval/imported3.wast
@@ -4,8 +4,6 @@
;; imports must not be used
(import "env" "tempDoublePtr" (global $tempDoublePtr i32))
(export "test1" $test1)
- (export "test2" $test2)
- (export "test3" $test3)
(global $mine (mut i32) (get_global $tempDoublePtr)) ;; BAD, if used
(func $test1
(drop (get_global $mine))
diff --git a/test/ctor-eval/imported3.wast.out b/test/ctor-eval/imported3.wast.out
index 0cbf32cea..101c1adaa 100644
--- a/test/ctor-eval/imported3.wast.out
+++ b/test/ctor-eval/imported3.wast.out
@@ -3,8 +3,6 @@
(memory $0 256 256)
(data (i32.const 10) "waka waka waka waka waka")
(export "test1" (func $test1))
- (export "test2" (func $test2))
- (export "test3" (func $test3))
(func $test1 (; 0 ;) (type $0)
(i32.store8
(i32.const 13)
diff --git a/test/ctor-eval/unsafe_call.wast b/test/ctor-eval/unsafe_call.wast
index 703760744..a3dff7c19 100644
--- a/test/ctor-eval/unsafe_call.wast
+++ b/test/ctor-eval/unsafe_call.wast
@@ -2,8 +2,6 @@
(memory 256 256)
(data (i32.const 10) "waka waka waka waka waka")
(export "test1" $test1)
- (export "test2" $test2)
- (export "test3" $test3)
(func $test1
(call $unsafe-to-call) ;; unsafe to call
(i32.store (i32.const 12) (i32.const 115)) ;; a safe store, should alter memory
diff --git a/test/ctor-eval/unsafe_call.wast.out b/test/ctor-eval/unsafe_call.wast.out
index 5a16a6112..d92a4cd2f 100644
--- a/test/ctor-eval/unsafe_call.wast.out
+++ b/test/ctor-eval/unsafe_call.wast.out
@@ -3,8 +3,6 @@
(memory $0 256 256)
(data (i32.const 10) "waka waka waka waka waka")
(export "test1" (func $test1))
- (export "test2" (func $test2))
- (export "test3" (func $test3))
(func $test1 (; 0 ;) (type $0)
(call $unsafe-to-call)
(i32.store
diff --git a/test/ctor-eval/unsafe_store.wast b/test/ctor-eval/unsafe_store.wast
index f851672a7..296363b35 100644
--- a/test/ctor-eval/unsafe_store.wast
+++ b/test/ctor-eval/unsafe_store.wast
@@ -2,8 +2,6 @@
(memory 256 256)
(data (i32.const 10) "waka waka waka waka waka")
(export "test1" $test1)
- (export "test2" $test2)
- (export "test3" $test3)
(func $test1
(i32.store8 (i32.const 9) (i32.const 109)) ;; before first segment
)
diff --git a/test/ctor-eval/unsafe_store.wast.out b/test/ctor-eval/unsafe_store.wast.out
index e51bd298d..4427f36e0 100644
--- a/test/ctor-eval/unsafe_store.wast.out
+++ b/test/ctor-eval/unsafe_store.wast.out
@@ -1,4 +1,2 @@
(module
- (export "test2" (func $test2))
- (export "test3" (func $test3))
)
diff --git a/test/ctor-eval/unsafe_store2.wast b/test/ctor-eval/unsafe_store2.wast
index cc5eb1105..5272c8333 100644
--- a/test/ctor-eval/unsafe_store2.wast
+++ b/test/ctor-eval/unsafe_store2.wast
@@ -2,8 +2,6 @@
(memory 256 256)
(data (i32.const 10) "waka waka waka waka waka")
(export "test1" $test1)
- (export "test2" $test2)
- (export "test3" $test3)
(func $test1
(i32.store8 (i32.const 34) (i32.const 109)) ;; after last segment
)
diff --git a/test/ctor-eval/unsafe_store2.wast.out b/test/ctor-eval/unsafe_store2.wast.out
index e51bd298d..4427f36e0 100644
--- a/test/ctor-eval/unsafe_store2.wast.out
+++ b/test/ctor-eval/unsafe_store2.wast.out
@@ -1,4 +1,2 @@
(module
- (export "test2" (func $test2))
- (export "test3" (func $test3))
)
diff --git a/test/ctor-eval/unsafe_store3.wast b/test/ctor-eval/unsafe_store3.wast
index 701e4b32e..b8e7c662a 100644
--- a/test/ctor-eval/unsafe_store3.wast
+++ b/test/ctor-eval/unsafe_store3.wast
@@ -2,8 +2,6 @@
(memory 256 256)
(data (i32.const 10) "waka waka waka waka waka")
(export "test1" $test1)
- (export "test2" $test2)
- (export "test3" $test3)
(func $test1
(i32.store16 (i32.const 33) (i32.const 109)) ;; after last segment due to size of type
)
diff --git a/test/ctor-eval/unsafe_store3.wast.out b/test/ctor-eval/unsafe_store3.wast.out
index e51bd298d..4427f36e0 100644
--- a/test/ctor-eval/unsafe_store3.wast.out
+++ b/test/ctor-eval/unsafe_store3.wast.out
@@ -1,4 +1,2 @@
(module
- (export "test2" (func $test2))
- (export "test3" (func $test3))
)