Skip to content

Commit

Permalink
fix another async serialize_packed EOF bug (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha authored Nov 8, 2023
1 parent 45744ca commit 18c5ca6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions capnp-futures/src/serialize_packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ where
// add a byte for the count of pass-through words
*buf_size = 10
}
if *buf_pos >= *buf_size {
// Skip the BufferingWord stage, because
// there is nothing left to buffer.
*stage = PackedReadStage::DrainingBuffer;
*buf_pos = 1;
}
}
}
}
Expand All @@ -139,6 +145,11 @@ where
PackedReadStage::BufferingWord => {
match Pin::new(&mut *inner).poll_read(cx, &mut buf[*buf_pos..*buf_size])? {
Poll::Pending => return Poll::Pending,
Poll::Ready(0) => {
return Poll::Ready(Err(std::io::Error::from(
std::io::ErrorKind::UnexpectedEof,
)))
}
Poll::Ready(n) => {
*buf_pos += n;
if *buf_pos >= *buf_size {
Expand Down Expand Up @@ -702,4 +713,16 @@ pub mod test {
.expect("reading");
assert!(message.is_none());
}

#[test]
fn eof_mid_message() {
let words = vec![0xfe, 0x3, 0x3];
let result =
futures::executor::block_on(Box::pin(try_read_message(&words[..], Default::default())));

match result {
Ok(_) => panic!("expected error"),
Err(e) => assert_eq!(e.kind, capnp::ErrorKind::PrematureEndOfFile),
}
}
}
1 change: 1 addition & 0 deletions capnp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ impl core::convert::From<::std::io::Error> for Error {
| io::ErrorKind::ConnectionReset
| io::ErrorKind::ConnectionAborted
| io::ErrorKind::NotConnected => ErrorKind::Disconnected,
io::ErrorKind::UnexpectedEof => ErrorKind::PrematureEndOfFile,
_ => ErrorKind::Failed,
};
#[cfg(feature = "alloc")]
Expand Down

0 comments on commit 18c5ca6

Please sign in to comment.