Skip to content

Commit

Permalink
Don't panic in wasmprinter with non-function types (#1114)
Browse files Browse the repository at this point in the history
This fixes an accidental regression from #1059 where an invalid wasm
file was causing a panic in wasmprinter, and wasmprinter shouldn't be
panicking on invalid wasm files.
  • Loading branch information
alexcrichton authored Jul 10, 2023
1 parent 6dae59e commit 4a568a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions crates/wasmprinter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,7 @@ impl Printer {
structural_type: StructuralType::Func(ty),
..
})) => self.print_func_type(state, ty, names_for).map(Some),
Some(Some(_)) => unreachable!("the core type must be a func"),
Some(None) | None => Ok(None),
Some(Some(_)) | Some(None) | None => Ok(None),
}
}

Expand Down
12 changes: 12 additions & 0 deletions crates/wasmprinter/tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,15 @@ fn offsets_and_lines_smoke_test() {

assert_eq!(actual, expected);
}

#[test]
fn no_panic_non_func_type() {
let bytes = wat::parse_str(
"(module
(type (struct))
(func (type 0))
)",
)
.unwrap();
wasmprinter::print_bytes(&bytes).unwrap();
}

0 comments on commit 4a568a3

Please sign in to comment.