From 49fcd2b76f919498deca6e4e8d292d9152255ad6 Mon Sep 17 00:00:00 2001 From: Evian-Zhang Date: Mon, 6 Jul 2026 22:55:11 +0800 Subject: [PATCH 1/2] Fix exception safety violation in AbiBuffer::advance --- crates/guest-rust/src/rt/async_support/abi_buffer.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/guest-rust/src/rt/async_support/abi_buffer.rs b/crates/guest-rust/src/rt/async_support/abi_buffer.rs index 9b0841999..0ec2e9632 100644 --- a/crates/guest-rust/src/rt/async_support/abi_buffer.rs +++ b/crates/guest-rust/src/rt/async_support/abi_buffer.rs @@ -133,6 +133,8 @@ impl AbiBuffer { let (mut ptr, len) = self.abi_ptr_and_len(); assert!(amt <= len); for _ in 0..amt { + // Update self.cursor incrementally for exception safety + self.cursor += 1; // SAFETY: we're managing the pointer passed to `dealloc_lists` and // it was initialized with a `lower`, and then the pointer // arithmetic should all be in-bounds. @@ -141,7 +143,6 @@ impl AbiBuffer { ptr = ptr.add(self.ops.elem_layout().size()); } } - self.cursor += amt; } fn take_vec(&mut self) -> Vec { From bf6f8c5710e74467506ee0991e51bcb7ff453467 Mon Sep 17 00:00:00 2001 From: Evian-Zhang Date: Mon, 6 Jul 2026 23:08:01 +0800 Subject: [PATCH 2/2] Add more explanation --- crates/guest-rust/src/rt/async_support/abi_buffer.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/guest-rust/src/rt/async_support/abi_buffer.rs b/crates/guest-rust/src/rt/async_support/abi_buffer.rs index 0ec2e9632..fe97b687e 100644 --- a/crates/guest-rust/src/rt/async_support/abi_buffer.rs +++ b/crates/guest-rust/src/rt/async_support/abi_buffer.rs @@ -133,7 +133,11 @@ impl AbiBuffer { let (mut ptr, len) = self.abi_ptr_and_len(); assert!(amt <= len); for _ in 0..amt { - // Update self.cursor incrementally for exception safety + // Update self.cursor incrementally for exception safety. + // When `self.ops.dealloc_lists` panics (which is a user-provided + // callback), we can make sure any item before (including the + // panic one) will not be dealloced again, and the remaining items + // can still get advanced properly. self.cursor += 1; // SAFETY: we're managing the pointer passed to `dealloc_lists` and // it was initialized with a `lower`, and then the pointer