Skip to content

Commit

Permalink
Increase URI MAX_LEN to 100_000
Browse files Browse the repository at this point in the history
**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).
  • Loading branch information
Mark Lodato committed Jan 6, 2021
1 parent 090badc commit 7c40d96
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/header/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ impl<T> HeaderMap<T> {
/// ```
pub fn reserve(&mut self, additional: usize) {
// TODO: This can't overflow if done properly... since the max # of
// elements is u16::MAX.
// elements is 100_000
let cap = self
.entries
.len()
Expand Down
4 changes: 2 additions & 2 deletions src/uri/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ enum ErrorKind {
SchemeTooLong,
}

// u16::MAX is reserved for None
const MAX_LEN: usize = (u16::MAX - 1) as usize;
// 100_001
const MAX_LEN: usize = 100_000;

const URI_CHARS: [u8; 256] = [
// 0 1 2 3 4 5 6 7 8 9
Expand Down
6 changes: 3 additions & 3 deletions src/uri/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use crate::byte_str::ByteStr;
#[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 = 100_001;

impl PathAndQuery {
// Not public while `bytes` is unstable.
Expand All @@ -32,7 +32,7 @@ impl PathAndQuery {
match b {
b'?' => {
debug_assert_eq!(query, NONE);
query = i as u16;
query = i as u32;
break;
}
b'#' => {
Expand Down
2 changes: 1 addition & 1 deletion src/uri/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,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'; u32::MAX as usize]);

let uri = String::from_utf8(uri).unwrap();
let res: Result<Uri, InvalidUri> = uri.parse();
Expand Down

0 comments on commit 7c40d96

Please sign in to comment.