diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 3ebd5d8ecba..7f385f16eb2 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -4733,12 +4733,15 @@ void WasmBinaryReader::readExports() { Expression* WasmBinaryReader::readExpression() { assert(builder.empty()); - while (input[pos] != BinaryConsts::End) { + while (more() && input[pos] != BinaryConsts::End) { auto inst = readInst(); if (auto* err = inst.getErr()) { throwError(err->msg); } } + if (!more()) { + throwError("unexpected end of input"); + } ++pos; auto expr = builder.build(); if (auto* err = expr.getErr()) {