Skip to content

Miri reports possible UB in Body #3014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/body/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,55 @@ mod tests {
assert!(rx.data().await.is_none());
}

use pin_project_lite::pin_project;

pin_project! {
#[derive(Debug)]
struct Inner {
#[pin]
body: Body,
}
}
Comment on lines +738 to +744
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Body type is Unpin so it doesn't make sense to pin it.


use crate::common::buf::BufList;
use bytes::Bytes;

impl Inner {
fn new(body: Body) -> Self {
Self { body }
}

async fn collect(self) -> std::result::Result<BufList<Bytes>, crate::Error> {
let mut output = BufList::new();
let body = self.body;
futures_util::pin_mut!(body);
while let Some(buf) = body.data().await {
output.push(buf?);
}
Ok(output)
}
}

use bytes::Buf;

#[tokio::test]
async fn read_from_channel_body() {
let (mut sender, body) = Body::channel();
let byte_stream = Inner::new(body);
tokio::spawn(async move {
sender.send_data(Bytes::from("data 1")).await.unwrap();
sender.send_data(Bytes::from("data 2")).await.unwrap();
sender.send_data(Bytes::from("data 3")).await.unwrap();
});

let mut aggregated_bytes: BufList<Bytes> = byte_stream.collect().await.expect("no errors");

assert_eq!(
aggregated_bytes.copy_to_bytes(aggregated_bytes.remaining()),
Bytes::from("data 1data 2data 3")
);
}

#[test]
fn channel_ready() {
let (mut tx, _rx) = Body::new_channel(DecodedLength::CHUNKED, /*wanter = */ false);
Expand Down