mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 00:21:08 +01:00
fe13789345
Fixes #1321 A better fix would be to change `MessageBody` to take a `Pin<&mut Self>`, rather than a `Pin<&mut Self>`. This will avoid requiring the use of `Box` for all consumers by allowing the caller to determine how to pin the `MessageBody` implementation (e.g. via stack pinning). However, doing so is a breaking change that will affect every user of `MessageBody`. By pinning the inner stream ourselves, we can fix the undefined behavior without breaking the API. I've included @sebzim4500's reproduction case as a new test case. However, due to the nature of undefined behavior, this could pass (and not segfault) even if underlying issue were to regress. Unfortunately, until rust-lang/unsafe-code-guidelines#148 is resolved, it's not even possible to write a Miri test that will pass when the bug is fixed. Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
27 lines
746 B
Rust
27 lines
746 B
Rust
// Regression test for #/1321
|
|
|
|
use futures::task::{noop_waker, Context};
|
|
use futures::stream::once;
|
|
use actix_http::body::{MessageBody, BodyStream};
|
|
use bytes::Bytes;
|
|
|
|
#[test]
|
|
fn weird_poll() {
|
|
let (sender, receiver) = futures::channel::oneshot::channel();
|
|
let mut body_stream = Ok(BodyStream::new(once(async {
|
|
let x = Box::new(0);
|
|
let y = &x;
|
|
receiver.await.unwrap();
|
|
let _z = **y;
|
|
Ok::<_, ()>(Bytes::new())
|
|
})));
|
|
|
|
let waker = noop_waker();
|
|
let mut context = Context::from_waker(&waker);
|
|
|
|
let _ = body_stream.as_mut().unwrap().poll_next(&mut context);
|
|
sender.send(()).unwrap();
|
|
let _ = std::mem::replace(&mut body_stream, Err([0; 32])).unwrap().poll_next(&mut context);
|
|
}
|
|
|