Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/wasmparser/src/validator/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,14 @@ where
/// breaks interact with this block's type. Additionally the type signature
/// of the block is specified by `ty`.
fn push_ctrl(&mut self, kind: FrameKind, ty: BlockType) -> Result<()> {
// If the control stack is already empty then that means that the
// function has already ended and it's invalid to have operators.
// Prevent pushing more frames to the control stack and immediately
// return an error.
if self.control.is_empty() {
return Err(self.err_beyond_end(self.offset));
}

// Push a new frame which has a snapshot of the height of the current
// operand stack.
let height = self.operands.len();
Expand Down
16 changes: 16 additions & 0 deletions tests/cli/block-after-frame.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
;; FAIL: validate %

(module
(func (param i32) (result i32)
i32.const 0
i32.const 0
br_if 0
i32.const 0
return
end
block
i32.const 0
return
end
)
)
4 changes: 4 additions & 0 deletions tests/cli/block-after-frame.wat.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: func 0 failed to validate

Caused by:
0: operators remaining after end of function (at offset 0x23)