Skip to content

Commit 00bb9b0

Browse files
committed
Assert that the buffer has free space before reading
1 parent 3d90045 commit 00bb9b0

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/imap_stream.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,13 @@ impl<R: Read + Write + Unpin> Stream for ImapStream<R> {
291291
this.buffer.ensure_capacity(this.decode_needs)?;
292292
let buf = this.buffer.free_as_mut_slice();
293293

294+
// The buffer should have at least one byte free
295+
// before we try reading into it
296+
// so we can treat 0 bytes read as EOF.
297+
// This is guaranteed by `ensure_capacity()` above
298+
// even if it is called with 0 as an argument.
299+
debug_assert!(buf.len() > 0);
300+
294301
#[cfg(feature = "runtime-async-std")]
295302
let num_bytes_read = ready!(Pin::new(&mut this.inner).poll_read(cx, buf))?;
296303

0 commit comments

Comments
 (0)