summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
4 files changed, 12 insertions, 2 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;