Skip to content

Commit 9cab6c9

Browse files
lexnvjxs
andauthored
yamux/frame: Ensure frame io does not panic on invalid write results (#202)
* yamux/frame: Ensure frame io does not panic on invalid write results Signed-off-by: Alexandru Vasile <[email protected]> * frame/io: Apply clippy Signed-off-by: Alexandru Vasile <[email protected]> --------- Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: João Oliveira <[email protected]>
1 parent 8bd29c4 commit 9cab6c9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

yamux/src/frame/io.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ impl<T: AsyncRead + AsyncWrite + Unpin> Sink<Frame<()>> for Io<T> {
101101
return Poll::Ready(Err(io::ErrorKind::WriteZero.into()));
102102
}
103103
*offset += n;
104+
105+
if *offset > header.len() {
106+
return Poll::Ready(Err(io::Error::other(format!(
107+
"Writer header returned invalid write count n={n}: {offset} > {} ",
108+
header.len(),
109+
))));
110+
}
111+
104112
if *offset == header.len() {
105113
if !buffer.is_empty() {
106114
let buffer = std::mem::take(buffer);
@@ -122,6 +130,14 @@ impl<T: AsyncRead + AsyncWrite + Unpin> Sink<Frame<()>> for Io<T> {
122130
return Poll::Ready(Err(io::ErrorKind::WriteZero.into()));
123131
}
124132
*offset += n;
133+
134+
if *offset > buffer.len() {
135+
return Poll::Ready(Err(io::Error::other(format!(
136+
"Writer body returned invalid write count n={n}: {offset} > {} ",
137+
buffer.len(),
138+
))));
139+
}
140+
125141
if *offset == buffer.len() {
126142
this.write_state = WriteState::Init;
127143
}

0 commit comments

Comments
 (0)