Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Fix processing of `assert_malformed` (#14001)

Alex Crichtonf92cc07de426
diff --git a/crates/wasmtime/src/runtime/component/component.rs b/crates/wasmtime/src/runtime/component/component.rs
index 7430cc716e..c07ba7f685 100644
--- a/crates/wasmtime/src/runtime/component/component.rs
+++ b/crates/wasmtime/src/runtime/component/component.rs
@@ -12,6 +12,7 @@ use crate::{
};
use crate::{FuncType, ValType};
use alloc::sync::Arc;
+use core::fmt;
use core::ops::Range;
use core::ptr::NonNull;
#[cfg(feature = "std")]
@@ -100,6 +101,12 @@ struct ComponentInner {
checksum: WasmChecksum,
}
+impl fmt::Debug for Component {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("Component").finish_non_exhaustive()
+ }
+}
+
pub(crate) struct AllCallFuncPointers {
pub wasm_call: NonNull<VMWasmCallFunction>,
pub array_call: NonNull<VMArrayCallFunction>,
diff --git a/crates/wast/src/wast.rs b/crates/wast/src/wast.rs
index 6cd40bfc06..6891956c4b 100644
--- a/crates/wast/src/wast.rs
+++ b/crates/wast/src/wast.rs
@@ -66,7 +66,7 @@ enum Results {
Component(Vec<component::Val>),
}
-#[derive(Clone)]
+#[derive(Clone, Debug)]
enum ModuleKind {
Core(Module),
#[cfg(feature = "component-model")]
@@ -415,10 +415,7 @@ impl WastContext {
/// This will not register the name within `self.modules`.
fn module_definition(&mut self, file: &WasmFile) -> Result<ModuleKind> {
let name = match file.module_type {
- WasmFileType::Text => file
- .binary_filename
- .as_ref()
- .ok_or_else(|| format_err!("cannot compile module that isn't a valid binary"))?,
+ WasmFileType::Text => file.binary_filename.as_ref().unwrap_or(&file.filename),
WasmFileType::Binary => &file.filename,
};
@@ -741,6 +738,11 @@ impl WastContext {
file,
text,
line: _,
+ }
+ | AssertMalformed {
+ file,
+ text,
+ line: _,
} => {
let err = match self.module_definition(&file) {
Ok(_) => bail!("expected module to fail to build"),
@@ -748,15 +750,6 @@ impl WastContext {
};
self.match_error_message(&text, err)?;
}
- AssertMalformed {
- file,
- text: _,
- line: _,
- } => {
- if let Ok(_) = self.module_definition(&file) {
- bail!("expected malformed module to fail to instantiate");
- }
- }
AssertUnlinkable {
file,
text,
diff --git a/tests/misc_testsuite/no-panic-on-invalid.wast b/tests/misc_testsuite/no-panic-on-invalid.wast
index 85dd7c4f55..1af80ccc1e 100644
--- a/tests/misc_testsuite/no-panic-on-invalid.wast
+++ b/tests/misc_testsuite/no-panic-on-invalid.wast
@@ -32,4 +32,4 @@
;; pretend this is the actual function end
"\0b" ;; end
)
- "hello")
+ "operators remaining after end")