diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 74d74f473f7..ee8afeb93ed 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -2243,7 +2243,15 @@ void WasmBinaryReader::verifyInt64(int64_t x) { void WasmBinaryReader::readHeader() { BYN_TRACE("== readHeader\n"); verifyInt32(BinaryConsts::Magic); - verifyInt32(BinaryConsts::Version); + auto version = getInt32(); + if (version != BinaryConsts::Version) { + if (version == 0x1000d) { + throwError("this looks like a wasm component, which Binaryen does not " + "support yet (see " + "https://github.com/WebAssembly/binaryen/issues/6728)"); + } + throwError("invalid version"); + } } void WasmBinaryReader::readStart() { diff --git a/test/lit/binary/component-error.test b/test/lit/binary/component-error.test new file mode 100644 index 00000000000..57bcec4573b --- /dev/null +++ b/test/lit/binary/component-error.test @@ -0,0 +1,6 @@ +# Verify that we show an error when given a component. + +;; RUN: not wasm-opt %s.wasm 2>&1 | filecheck %s + +;; CHECK: this looks like a wasm component, which Binaryen does not support yet (see https://github.com/WebAssembly/binaryen/issues/6728) + diff --git a/test/lit/binary/component-error.test.wasm b/test/lit/binary/component-error.test.wasm new file mode 100644 index 00000000000..13d20e9f03e Binary files /dev/null and b/test/lit/binary/component-error.test.wasm differ