Skip to content
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

panic on extremely long urls #1934

Open
jcfj opened this issue Aug 9, 2023 · 0 comments
Open

panic on extremely long urls #1934

jcfj opened this issue Aug 9, 2023 · 0 comments

Comments

@jcfj
Copy link

jcfj commented Aug 9, 2023

The following code

//! ```cargo
//! [dependencies]
//! itertools = "0.11.0"
//! reqwest = "0.11.18"
//! serde_json = "1.0.104"
//! reqwest = { version = "0.11.18", features = ["json"] }
//! tokio = { version = "1.29.1", features = ["full"] }
//! ```

use itertools::Itertools;

#[tokio::main]
async fn main() {
    let url = reqwest::Url::parse(&format!(
        "http://router.project-osrm.org/table/v1/driving/{}?sources=0",
        (0..5000).map(|i| format!("13.{i:04},52.4242")).join(";")
    ))
    .unwrap();
    dbg!(url.as_str());
    dbg!(reqwest::get(url)
        .await
        .unwrap()
        .json::<serde_json::Value>()
        .await
        .unwrap());
}

will trigger

thread 'main' panicked at 'a parsed Url should always be a valid Uri: InvalidUri(TooLong)', /home/julius/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.11.18/src/into_url.rs:80:14
stack backtrace:
   0: rust_begin_unwind
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:67:14
   2: core::result::unwrap_failed
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/result.rs:1651:5
   3: core::result::Result<T,E>::expect
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/result.rs:1033:23
   4: reqwest::into_url::expect_uri
             at /home/julius/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.11.18/src/into_url.rs:78:9
   5: reqwest::async_impl::client::Client::execute_request
             at /home/julius/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.11.18/src/async_impl/client.rs:1679:19
   6: reqwest::async_impl::request::RequestBuilder::send
             at /home/julius/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.11.18/src/async_impl/request.rs:509:24
   7: reqwest::get::{{closure}}
             at /home/julius/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.11.18/src/lib.rs:287:5
   8: repro::main::{{closure}}
             at ./src/main.rs:26:10

I'm not sure how this would be best resolved. There currently is a hard-coded maximum length in http and several similar issues have already been reported, ending in a PR that would bubble up that error instead of panicking. But personally, I'd very much like it if I could send this HTTP request. router.project-osrm.org may not respond to it, but if running the underlying osrm software locally, it is both possible and meaningful to make these (somewhat insanely) large requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant