Skip to content

Commit 3381de5

Browse files
committed
Assert that the buffer has free space before reading
1 parent 12b0446 commit 3381de5

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
@@ -278,6 +278,13 @@ impl<R: Read + Write + Unpin> Stream for ImapStream<R> {
278278
this.buffer.ensure_capacity(this.decode_needs)?;
279279
let buf = this.buffer.free_as_mut_slice();
280280

281+
// The buffer should have at least one byte free
282+
// before we try reading into it
283+
// so we can treat 0 bytes read as EOF.
284+
// This is guaranteed by `ensure_capacity()` above
285+
// even if it is called with 0 as an argument.
286+
debug_assert!(buf.len() > 0);
287+
281288
#[cfg(feature = "runtime-async-std")]
282289
let num_bytes_read = ready!(Pin::new(&mut this.inner).poll_read(cx, buf))?;
283290

0 commit comments

Comments
 (0)