From f59401fe519fa46352fadfedc9e33906ac89b359 Mon Sep 17 00:00:00 2001 From: Mark Lodato Date: Wed, 6 Jan 2021 12:18:13 -0500 Subject: [PATCH] Increase URI MAX_LEN to 150_000 **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](https://github.com/seanmonstar/reqwest/issues/668). --- src/header/map.rs | 6 ++++-- src/uri/mod.rs | 4 ++-- src/uri/path.rs | 6 +++--- src/uri/tests.rs | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/header/map.rs b/src/header/map.rs index 2bb62b55..6c763a1a 100644 --- a/src/header/map.rs +++ b/src/header/map.rs @@ -629,8 +629,10 @@ impl HeaderMap { /// ``` pub fn reserve(&mut self, additional: usize) { // TODO: This can't overflow if done properly... since the max # of - // elements is u16::MAX. - let cap = self.entries.len() + // elements is 150_000 + let cap = self + .entries + .len() .checked_add(additional) .expect("reserve overflow"); diff --git a/src/uri/mod.rs b/src/uri/mod.rs index 0d2f34b8..058baf92 100644 --- a/src/uri/mod.rs +++ b/src/uri/mod.rs @@ -147,8 +147,8 @@ enum ErrorKind { SchemeTooLong, } -// u16::MAX is reserved for None -const MAX_LEN: usize = (u16::MAX - 1) as usize; +// 150_001 is for NONE +const MAX_LEN: usize = 150_000; const URI_CHARS: [u8; 256] = [ // 0 1 2 3 4 5 6 7 8 9 diff --git a/src/uri/path.rs b/src/uri/path.rs index 2cafbf89..a7da257c 100644 --- a/src/uri/path.rs +++ b/src/uri/path.rs @@ -11,10 +11,10 @@ use super::{ErrorKind, InvalidUri, InvalidUriBytes}; #[derive(Clone)] pub struct PathAndQuery { pub(super) data: ByteStr, - pub(super) query: u16, + pub(super) query: u32, } -const NONE: u16 = ::std::u16::MAX; +const NONE: u32 = 150_001; impl PathAndQuery { /// Attempt to convert a `PathAndQuery` from `Bytes`. @@ -57,7 +57,7 @@ impl PathAndQuery { match b { b'?' => { debug_assert_eq!(query, NONE); - query = i as u16; + query = i as u32; break; } b'#' => { diff --git a/src/uri/tests.rs b/src/uri/tests.rs index 9a9ccc80..25ec01ed 100644 --- a/src/uri/tests.rs +++ b/src/uri/tests.rs @@ -445,7 +445,7 @@ fn test_uri_parse_error() { fn test_max_uri_len() { let mut uri = vec![]; uri.extend(b"http://localhost/"); - uri.extend(vec![b'a'; 70 * 1024]); + uri.extend(vec![b'a'; 150_001]); let uri = String::from_utf8(uri).unwrap(); let res: Result = uri.parse();