Skip to content

Commit cc24f5d

Browse files
fix: avoid infinite loop in decoding
1 parent dbddd3b commit cc24f5d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/imap_stream.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ impl<R: Read + Write + Unpin> ImapStream<R> {
109109
start: usize,
110110
end: usize,
111111
) -> io::Result<DecodeResult> {
112-
if self.decode_needs > end - start {
113-
return Ok(DecodeResult::None(buf));
114-
}
115-
116112
log::trace!("< {:?}", std::str::from_utf8(&buf[start..end]));
117113

118114
let mut rest = None;
@@ -186,9 +182,9 @@ impl<R: Read + Write + Unpin> Stream for ImapStream<R> {
186182
};
187183

188184
loop {
189-
if (n.1 - n.0) >= buffer.capacity() {
190-
if buffer.capacity() + 1024 < MAX_CAPACITY {
191-
buffer.realloc(buffer.capacity() + 1024);
185+
if (n.1 - n.0) + this.decode_needs >= buffer.capacity() {
186+
if buffer.capacity() + this.decode_needs < MAX_CAPACITY {
187+
buffer.realloc(buffer.capacity() + this.decode_needs);
192188
} else {
193189
return Poll::Ready(Some(Err(io::Error::new(
194190
io::ErrorKind::Other,

0 commit comments

Comments
 (0)