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
16 changes: 16 additions & 0 deletions yamux/src/frame/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ impl<T: AsyncRead + AsyncWrite + Unpin> Sink<Frame<()>> for Io<T> {
return Poll::Ready(Err(io::ErrorKind::WriteZero.into()));
}
*offset += n;

if *offset > header.len() {
return Poll::Ready(Err(io::Error::other(format!(
"Writer header returned invalid write count n={n}: {offset} > {} ",
header.len(),
))));
}

if *offset == header.len() {
if !buffer.is_empty() {
let buffer = std::mem::take(buffer);
Expand All @@ -122,6 +130,14 @@ impl<T: AsyncRead + AsyncWrite + Unpin> Sink<Frame<()>> for Io<T> {
return Poll::Ready(Err(io::ErrorKind::WriteZero.into()));
}
*offset += n;

if *offset > buffer.len() {
return Poll::Ready(Err(io::Error::other(format!(
"Writer body returned invalid write count n={n}: {offset} > {} ",
buffer.len(),
))));
}

if *offset == buffer.len() {
this.write_state = WriteState::Init;
}
Expand Down