diff --git a/src/parser/WASMParser.cpp b/src/parser/WASMParser.cpp index 69a9b0ac4..08152d5ef 100644 --- a/src/parser/WASMParser.cpp +++ b/src/parser/WASMParser.cpp @@ -535,9 +535,9 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate { m_vmStack.push_back(VMStackInfo(*this, type, pos, m_functionStackSizeSoFar, localIndex)); size_t allocSize = Walrus::valueStackAllocatedSize(type); - if (UNLIKELY(m_functionStackSizeSoFar + allocSize > std::numeric_limits::max())) { - throw std::string("too many stack usage. we could not support this(yet)."); - } + // FIXME too many stack usage. we could not support this(yet) + ASSERT(m_functionStackSizeSoFar + allocSize <= std::numeric_limits::max()); + m_functionStackSizeSoFar += allocSize; m_currentFunction->m_requiredStackSize = std::max( m_currentFunction->m_requiredStackSize, m_functionStackSizeSoFar); @@ -545,6 +545,10 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate { VMStackInfo popVMStackInfo() { + // FIXME This error can occur during the parsing process because of invalid wasm instructions + // e.g. a function with no end opcode + ASSERT(m_vmStack.size() > 0); + auto info = m_vmStack.back(); m_functionStackSizeSoFar -= Walrus::valueStackAllocatedSize(info.valueType()); m_vmStack.pop_back(); @@ -567,24 +571,27 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate { return info; } - size_t popVMStack() + VMStackInfo& peekVMStackInfo() { - return popVMStackInfo().position(); + // FIXME This error can occur during the parsing process because of invalid wasm instructions + // e.g. a function with no end opcode + ASSERT(m_vmStack.size() > 0); + return m_vmStack.back(); } - size_t peekVMStack() + size_t popVMStack() { - return m_vmStack.back().position(); + return popVMStackInfo().position(); } - VMStackInfo& peekVMStackInfo() + size_t peekVMStack() { - return m_vmStack.back(); + return peekVMStackInfo().position(); } Walrus::Value::Type peekVMStackValueType() { - return m_vmStack.back().valueType(); + return peekVMStackInfo().valueType(); } void beginFunction(Walrus::ModuleFunction* mf, bool inInitExpr) diff --git a/third_party/wabt/src/walrus/binary-reader-walrus.cc b/third_party/wabt/src/walrus/binary-reader-walrus.cc index cc6584da6..d8fe2883c 100644 --- a/third_party/wabt/src/walrus/binary-reader-walrus.cc +++ b/third_party/wabt/src/walrus/binary-reader-walrus.cc @@ -1350,16 +1350,16 @@ std::string ReadWasmBinary(const std::string &filename, const uint8_t *data, siz const bool kFailOnCustomSectionError = true; ReadBinaryOptions options(getFeatures(), nullptr, kReadDebugNames, kStopOnFirstError, kFailOnCustomSectionError); BinaryReaderDelegateWalrus binaryReaderDelegateWalrus(delegate, filename); - try { - ReadBinary(data, size, &binaryReaderDelegateWalrus, options); - } catch(const std::string& err) { - // error from WASMBinaryReader - return err; - } + Result result = ReadBinary(data, size, &binaryReaderDelegateWalrus, options); - if (binaryReaderDelegateWalrus.m_errors.size()) { + if (WABT_UNLIKELY(binaryReaderDelegateWalrus.m_errors.size())) { return std::move(binaryReaderDelegateWalrus.m_errors.begin()->message); } + + if (WABT_UNLIKELY(result != ::wabt::Result::Ok)) { + return std::string("read wasm error"); + } + return std::string(); } diff --git a/tools/run-tests.py b/tools/run-tests.py index 4d19d347a..0b489fa84 100755 --- a/tools/run-tests.py +++ b/tools/run-tests.py @@ -114,7 +114,7 @@ def run_core_tests(engine): @runner('wasi', default=True) -def run_basic_tests(engine): +def run_wasi_tests(engine): TEST_DIR = join(PROJECT_SOURCE_DIR, 'test', 'wasi') print('Running wasi tests:') @@ -132,7 +132,7 @@ def run_basic_tests(engine): @runner('jit', default=True) -def run_basic_tests(engine): +def run_jit_tests(engine): TEST_DIR = join(PROJECT_SOURCE_DIR, 'test', 'jit') print('Running jit tests:') @@ -142,7 +142,7 @@ def run_basic_tests(engine): tests_total = len(xpass) fail_total = xpass_result print('TOTAL: %d' % (tests_total)) - print('%sPASS : %d%s' % (COLOR_GREEN, tests_total, COLOR_RESET)) + print('%sPASS : %d%s' % (COLOR_GREEN, tests_total - fail_total, COLOR_RESET)) print('%sFAIL : %d%s' % (COLOR_RED, fail_total, COLOR_RESET)) if fail_total > 0: