-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 when making request, could not parse Url as Uri #668
Comments
Repro'd on the |
Here are a few other random ones that came up in my logs, parseable as "http://‘nvme@nip2"
"http://-1@"
"https://a@b"
"https://€@qq" |
As a non-ideal bandage, I'm using these in the short term: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url
|
Thanks, as a workaround, I'm currently actually testing whether it will parse as |
I believe |
Not sure, it might be. But the panic came up because an But in the end I think this issue should be fixed no matter what, of course. |
I've also hit this bug, on URLs that contain "<" and ">". LIke @timvisee I am parsing URLs as It seems to me that reqwest should parse as |
I don't think I believe #668 (comment) is correct, in that the best approach would be to fix the |
I don't believe this is necessarily a bug in As you've mentioned, reqwest should likely check sooner that the URL can also be a valid URI. |
My code panicked tonight and because the fix should be the same, I’m adding my example to this issue. I am using a Telegram bot to inform me when something goes wrong. To send a message, you call a URL and pass the message in the query part of it. Unfortunately, because I included some logs in that message, the URL got too long and reqwest paniced at I’d expect that Example to reproduceuse reqwest::blocking::Client; // reqwest 0.10.9
use url::Url; // url 2.2.0
fn main() {
let text = "abcdefghijklmnopqrstuvwxyz".repeat(100_000);
let mut url = Url::parse("https://www.example.com/").unwrap();
url.query_pairs_mut().append_pair("text", &text);
Client::new()
.get(url)
.send() // panics
.expect("THIS IS NOT REACHED");
} [package]
name = "bug"
version = "0.1.0"
edition = "2018"
[dependencies]
reqwest = { version = "0.10.9", features = [ "blocking" ] }
url = "2.2.0" |
@gralpli I'm pretty sure your issue here is because you have way to much char in your url due to the Can you try without the repeat and check if it works? |
@Martichou Yes, the intended issue is that the URL is too long. But it is reqwest‘s |
@gralpli Oh yeah I see what you mean. |
**This Commit** Increases the max length of URIs to be u32::MAX - 1 **Why?** STEM can receive requests > u16::MAX. When it tries to forward these requests to Impeller, `reqwest` crashes when parsing the URL into a URI because `http` returns a `Result::Err`. This is currently being tracked [here](seanmonstar/reqwest#668).
**This Commit** Increases the max length of URIs to be u32::MAX - 1 **Why?** STEM can receive requests > u16::MAX. When it tries to forward these requests to Impeller, `reqwest` crashes when parsing the URL into a URI because `http` returns a `Result::Err`. This is currently being tracked [here](seanmonstar/reqwest#668).
**This Commit** Increases the max length of URIs to be u32::MAX - 1 **Why?** STEM can receive requests > u16::MAX. When it tries to forward these requests to Impeller, `reqwest` crashes when parsing the URL into a URI because `http` returns a `Result::Err`. This is currently being tracked [here](seanmonstar/reqwest#668).
**This Commit** Increases the max length of URIs to be 100_00 **Why?** STEM can receive requests > u16::MAX. When it tries to forward these requests to Impeller, `reqwest` crashes when parsing the URL into a URI because `http` returns a `Result::Err`. This is currently being tracked [here](seanmonstar/reqwest#668).
**This Commit** Increases the max length of URIs to be 100_000 **Why?** STEM can receive requests > u16::MAX. When it tries to forward these requests to Impeller, `reqwest` crashes when parsing the URL into a URI because `http` returns a `Result::Err`. This is currently being tracked [here](seanmonstar/reqwest#668).
**This Commit** Increases the max length of URIs to be 100_000 **Why?** STEM can receive requests > u16::MAX. When it tries to forward these requests to Impeller, `reqwest` crashes when parsing the URL into a URI because `http` returns a `Result::Err`. This is currently being tracked [here](seanmonstar/reqwest#668).
**This Commit** Increases the max length of URIs to be 150_000 **Why?** STEM can receive requests > u16::MAX. When it tries to forward these requests to Impeller, `reqwest` crashes when parsing the URL into a URI because `http` returns a `Result::Err`. This is currently being tracked [here](seanmonstar/reqwest#668).
**This Commit** Increases the max length of URIs to be 150_000 **Why?** STEM can receive requests > u16::MAX. When it tries to forward these requests to Impeller, `reqwest` crashes when parsing the URL into a URI because `http` returns a `Result::Err`. This is currently being tracked [here](seanmonstar/reqwest#668).
**This Commit** Increases the max length of URIs to be 150_000 **Why?** STEM can receive requests > u16::MAX. When it tries to forward these requests to Impeller, `reqwest` crashes when parsing the URL into a URI because `http` returns a `Result::Err`. This is currently being tracked [here](seanmonstar/reqwest#668).
**This Commit** Increases the max length of URIs to be 150_000 **Why?** STEM can receive requests > u16::MAX. When it tries to forward these requests to Impeller, `reqwest` crashes when parsing the URL into a URI because `http` returns a `Result::Err`. This is currently being tracked [here](seanmonstar/reqwest#668).
**This Commit** Increases the max length of URIs **Why?** STEM can receive requests > u16::MAX. When it tries to forward these requests to Impeller, `reqwest` crashes when parsing the URL into a URI because `http` returns a `Result::Err`. This is currently being tracked [here](seanmonstar/reqwest#668).
**This Commit** Increases the max length of URIs **Why?** STEM can receive requests > u16::MAX. When it tries to forward these requests to Impeller, `reqwest` crashes when parsing the URL into a URI because `http` returns a `Result::Err`. This is currently being tracked [here](seanmonstar/reqwest#668).
**This Commit** Increases the max length of URIs **Why?** STEM can receive requests > u16::MAX. When it tries to forward these requests to Impeller, `reqwest` crashes when parsing the URL into a URI because `http` returns a `Result::Err`. This is currently being tracked [here](seanmonstar/reqwest#668).
**This Commit** Increases the max length of URIs **Why?** STEM can receive requests > u16::MAX. When it tries to forward these requests to Impeller, `reqwest` crashes when parsing the URL into a URI because `http` returns a `Result::Err`. This is currently being tracked [here](seanmonstar/reqwest#668).
Instead propagate this parsing issue up to the calling function as a Result. See seanmonstar#668
Hitting a panic instead of a err'ed This bit me as well recently in a similar way to @gralpli above:
I now convert the String to a URL via In reading the get docs during writing the code I somehow parsed "This method fails whenever the supplied Url cannot be parsed." as thinking I'd get a bad |
Added a regression test. Reqwest fixed the issue upstream. seanmonstar/reqwest#668 GitOrigin-RevId: c58c994841934fc15530a0eea612aa9dea130b3d
With the upgrade to `reqwest` 0.12, we can finally handle a long-standing issue, when Urls could not be parsed to Uris. Previously, we would panic, but we can now handle that situation gracefully and return an error instead. I've also renamed `Status::is_failure` to `Status::is_error`, because the notion of failures no longer exists in the codebase and we use the term "error" consistently throughout the codebase instead. This is technically a breaking change in the API, but it's fine since we have not released a stable version yet. More information about the URI parsing issue: - #539 - seanmonstar/reqwest#668
With the upgrade to `reqwest` 0.12, we can finally handle a long-standing issue, when Urls could not be parsed to Uris. Previously, we would panic, but we can now handle that situation gracefully and return an error instead. I've also renamed `Status::is_failure` to `Status::is_error`, because the notion of failures no longer exists in the codebase and we use the term "error" consistently throughout the codebase instead. This is technically a breaking change in the API, but it's fine since we have not released a stable version yet. More information about the URI parsing issue: - #539 - seanmonstar/reqwest#668
Instead propagate this parsing issue up to the calling function as a Result. See seanmonstar#668 Original PR: seanmonstar#1399 Co-authored-by: Matthias <matthias-endler@gmx.net>
I just came across a panic in the latest
reqwest
release (both0.10
andmaster
). This happens when making a request.It seems that some input in
Client.get(url)
parses successfully as URL at first, and then panics when attempting to parse the URL ashttp::Uri
(internally).Example
Here's a very basic (abstracted) example that causes this panic:
Which outputs:
I believe the
Client.get(url)
function should return an error in all cases where the URL is invalid. This actually happens when providing something like"http://a b"
(InvalidDomainCharacter
). However,"http://\""
succeeds and panics when making the request with.send()
.The panic is located here.
Assumption
I have the following assumption on what is going on:
I think
Url
is used first to parse the provided URL (here). Then the assumption is made this URL is valid once parsing succeeds. Internally, when making a request throughhyper
, this URL is parsed to anUri
. Assuming the URL is valid this should always succeed, but it does not. That probably means that either implementation ofUrl
orUri
is incorrect, or at least not compatible.Al right. I'm not too familiar with the URL/URI specs, and don't want to go through it right now, to confirm either implementation is correct.
Fixing this
I see the following options:
Uri
when creating the request (and check for validity).Url
implementation (if invalid)Uri
implementation (if invalid)Uri
throughout the crate.Result
.I think the first is easiest to do on a short notice.
What would be the correct way of doing things? What are your thoughts, is the assumption I made right, and is this undesired behaviour?
I might be happy to implement a fix for this in code once I know what path I should take.
The text was updated successfully, but these errors were encountered: