Skip to content
New issue

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

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

Already on GitHub? # to your account

"Transfer-Encoding" correction code causes a panic #2409

Closed
inikulin opened this issue Jan 26, 2021 · 0 comments · Fixed by #2410
Closed

"Transfer-Encoding" correction code causes a panic #2409

inikulin opened this issue Jan 26, 2021 · 0 comments · Fixed by #2410
Labels
A-client Area: client. A-http1 Area: HTTP/1 specific. C-bug Category: bug. Something is wrong. This is bad! E-easy Effort: easy. A task that would be a great starting point for a new contributor.

Comments

@inikulin
Copy link
Contributor

inikulin commented Jan 26, 2021

Repro code:

use hyper::server::Server;
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Client, Request, Response};
use std::convert::Infallible;

#[tokio::main]
async fn main() {
     let make_service = make_service_fn(|_conn| async {
        Ok::<_, Infallible>(service_fn(|_| async {
            Ok::<_, Infallible>(Response::builder().body(Body::empty()).unwrap())
        }))
    });

    let server = Server::bind(&"127.0.0.1:0".parse().unwrap()).serve(make_service);
    let addr = server.local_addr();

    tokio::spawn(async move {
        server.await.unwrap();
    });

    let req = Request::builder()
        .method("GET")
        .header("Transfer-Encoding", "foo")
        .uri(format!("http://{}", addr))
        .body(Body::from("foobar"))
        .unwrap();

    assert!(Client::new().request(req).await.is_ok());
}

This panics with "source slice length (3) does not match destination slice length (0)". Apparently the reason is that only capacity is set for the target buffer here:

let mut buf = BytesMut::with_capacity(new_cap);
, but the buffer itself is not filled, so slice copying fails.

inikulin added a commit to inikulin/hyper that referenced this issue Jan 26, 2021
seanmonstar added a commit to inikulin/hyper that referenced this issue Jan 26, 2021
@seanmonstar seanmonstar added A-client Area: client. A-http1 Area: HTTP/1 specific. E-easy Effort: easy. A task that would be a great starting point for a new contributor. C-bug Category: bug. Something is wrong. This is bad! labels Jan 26, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-client Area: client. A-http1 Area: HTTP/1 specific. C-bug Category: bug. Something is wrong. This is bad! E-easy Effort: easy. A task that would be a great starting point for a new contributor.
Projects
None yet
2 participants