Skip to content

Commit 7bb5b8e

Browse files
committed
fix: return Err when async read returns no bytes
When read() returns with zero bytes read, this indicates an EOF. Previously, we'd continue to read() in a loop and never return to the caller if that happend. Fix this by returning a ProtocolError with ErrorKind::ConnectionAborted "read zero bytes". This results in an ProtocolFailureSuggestion::Abort. fixes #159
1 parent 8c46943 commit 7bb5b8e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

protocol/src/futures.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,15 @@ where
406406
bytes_read,
407407
} => {
408408
while *bytes_read < NUM_LENGTH_BYTES {
409-
*bytes_read += self.reader.read(&mut length_bytes[*bytes_read..]).await?;
409+
let len = self.reader.read(&mut length_bytes[*bytes_read..]).await?;
410+
if len == 0 {
411+
return Err(std::io::Error::new(
412+
std::io::ErrorKind::ConnectionAborted,
413+
"read zero bytes",
414+
)
415+
.into());
416+
}
417+
*bytes_read += len;
410418
}
411419

412420
let packet_bytes_len = self.inbound_cipher.decrypt_packet_len(*length_bytes);
@@ -417,7 +425,15 @@ where
417425
bytes_read,
418426
} => {
419427
while *bytes_read < packet_bytes.len() {
420-
*bytes_read += self.reader.read(&mut packet_bytes[*bytes_read..]).await?;
428+
let len = self.reader.read(&mut packet_bytes[*bytes_read..]).await?;
429+
if len == 0 {
430+
return Err(std::io::Error::new(
431+
std::io::ErrorKind::ConnectionAborted,
432+
"read zero bytes",
433+
)
434+
.into());
435+
}
436+
*bytes_read += len;
421437
}
422438

423439
let plaintext_len = InboundCipher::decryption_buffer_len(packet_bytes.len());

0 commit comments

Comments
 (0)