Skip to content

Commit c78f891

Browse files
authored
Handle OOM in wasmtime_environ::types::WasmFuncType's serde support (bytecodealliance#12672)
* Handle OOM in `WasmFuncType`'s `serde` support * Use `serde(deserialize_with = ..)` instead of full custom serde impl
1 parent e6948e7 commit c78f891

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

crates/environ/src/types.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ pub enum WasmHeapBottomType {
689689
/// WebAssembly function type -- equivalent of `wasmparser`'s FuncType.
690690
#[derive(Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
691691
pub struct WasmFuncType {
692+
#[serde(deserialize_with = "WasmFuncType::deserialize_params_results")]
692693
params_results: Box<[WasmValType]>,
693694
params_len: u32,
694695
non_i31_gc_ref_params_count: u32,
@@ -750,6 +751,18 @@ impl TypeTrace for WasmFuncType {
750751
}
751752

752753
impl WasmFuncType {
754+
fn deserialize_params_results<'de, D>(deserializer: D) -> Result<Box<[WasmValType]>, D::Error>
755+
where
756+
D: serde::de::Deserializer<'de>,
757+
{
758+
let tys: crate::collections::Vec<WasmValType> =
759+
serde::Deserialize::deserialize(deserializer)?;
760+
let tys = tys
761+
.into_boxed_slice()
762+
.map_err(|oom| serde::de::Error::custom(oom))?;
763+
Ok(tys)
764+
}
765+
753766
/// Creates a new function type from the provided `params` and `returns`.
754767
#[inline]
755768
pub fn new(

0 commit comments

Comments
 (0)