Skip to content

Commit 679ba8a

Browse files
committed
fix bug pushing a zero-sized function frame
We now return a NULL ptr for Sp since a zero-sized function frame may never access slots.
1 parent c351af7 commit 679ba8a

File tree

1 file changed

+12
-3
lines changed
  • crates/wasmi/src/engine/executor/handler

1 file changed

+12
-3
lines changed

crates/wasmi/src/engine/executor/handler/state.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ impl Sp {
154154
}
155155
}
156156

157+
pub fn null() -> Self {
158+
Self {
159+
value: ptr::null_mut(),
160+
}
161+
}
162+
157163
pub fn get<T>(self, slot: Slot) -> T
158164
where
159165
UntypedVal: ReadAs<T>,
@@ -276,9 +282,12 @@ impl ValueStack {
276282
Sp::new(&mut self.cells, start)
277283
}
278284

279-
fn push(&mut self, start: usize, size: usize, len_params: u16) -> Result<Sp, TrapCode> {
280-
debug_assert!(usize::from(len_params) <= size);
281-
let Some(end) = start.checked_add(size) else {
285+
fn push(&mut self, start: usize, len_slots: usize, len_params: u16) -> Result<Sp, TrapCode> {
286+
debug_assert!(usize::from(len_params) <= len_slots);
287+
if len_slots == 0 {
288+
return Ok(Sp::null());
289+
}
290+
let Some(end) = start.checked_add(len_slots) else {
282291
return Err(TrapCode::StackOverflow);
283292
};
284293
if end > self.max_height {

0 commit comments

Comments
 (0)