Skip to content

Commit

Permalink
Fix a panic in processing malformed input (#297)
Browse files Browse the repository at this point in the history
With the recent change to support full expressions in element segments
there's at least one missing location where an expression needed to get
processed for type expansion which was forgotten.
  • Loading branch information
alexcrichton authored Jun 30, 2021
1 parent 6d4f1b6 commit 633b624
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/wasmparser/src/readers/element_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ impl<'a> ElementItemsReader<'a> {
let ret = match self.reader.read_operator()? {
Operator::RefNull { ty } => ElementItem::Null(ty),
Operator::RefFunc { function_index } => ElementItem::Func(function_index),
_ => return Err(BinaryReaderError::new("invalid passive segment", offset)),
_ => return Err(BinaryReaderError::new("invalid element segment", offset)),
};
match self.reader.read_operator()? {
Operator::End => {}
_ => return Err(BinaryReaderError::new("invalid passive segment", offset)),
_ => return Err(BinaryReaderError::new("invalid element segment", offset)),
}
Ok(ret)
} else {
Expand Down
5 changes: 5 additions & 0 deletions crates/wast/src/resolve/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ impl<'a> Expander<'a> {
if let ElemKind::Active { offset, .. } = &mut e.kind {
self.expand_expression(offset);
}
if let ElemPayload::Exprs { exprs, .. } = &mut e.payload {
for expr in exprs {
self.expand_expression(expr);
}
}
}
ModuleField::Tag(t) => match &mut t.ty {
TagType::Exception(ty) => {
Expand Down
7 changes: 7 additions & 0 deletions tests/local/elem.wast
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@
)
"type mismatch"
)
(assert_invalid
(module
(table 1 funcref)
(elem (i32.const 0) funcref (if))
)
"invalid element segment"
)

0 comments on commit 633b624

Please sign in to comment.