Skip to content
Merged
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
11 changes: 9 additions & 2 deletions crates/guest-rust/src/rt/async_support/stream_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ use {
},
};

/// Maximum size of a read/write operation as specified by the canonical ABI.
const MAX_LENGTH: usize = (1 << 28) - 1;

/// Operations that a stream requires throughout the implementation.
///
/// This is generated by `wit_bindgen::generate!` primarily.
Expand Down Expand Up @@ -376,7 +379,11 @@ where
let (ptr, len) = buf.abi_ptr_and_len();
// SAFETY: sure hope this is safe, everything in this module and
// `AbiBuffer` is trying to make this safe.
let code = unsafe { self.writer.ops.start_write(self.writer.handle, ptr, len) };
let code = unsafe {
self.writer
.ops
.start_write(self.writer.handle, ptr, len.min(MAX_LENGTH))
};
rtdebug!(
"stream.write({}, {ptr:?}, {len}) = {code:#x}",
self.writer.handle
Expand Down Expand Up @@ -618,7 +625,7 @@ unsafe impl<'a, O: StreamOps> WaitableOp for StreamReadOp<'a, O> {
let code = unsafe {
self.reader
.ops
.start_read(self.reader.handle(), ptr, cap.len())
.start_read(self.reader.handle(), ptr, cap.len().min(MAX_LENGTH))
};
rtdebug!(
"stream.read({}, {ptr:?}, {}) = {code:#x}",
Expand Down
Loading