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

fix: HeaderName::from_lowercase allowing NUL bytes in some cases #684

Merged
merged 1 commit into from Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/header/name.rs
Expand Up @@ -1176,9 +1176,9 @@ impl HeaderName {
}
Repr::Custom(MaybeLower { buf, lower: false }) => {
for &b in buf.iter() {
// HEADER_CHARS maps all bytes that are not valid single-byte
// HEADER_CHARS_H2 maps all bytes that are not valid single-byte
// UTF-8 to 0 so this check returns an error for invalid UTF-8.
if b != HEADER_CHARS[b as usize] {
if HEADER_CHARS_H2[b as usize] == 0 {
return Err(InvalidHeaderName::new());
}
}
Expand Down Expand Up @@ -1904,4 +1904,16 @@ mod tests {
fn test_all_tokens() {
HeaderName::from_static("!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyz");
}

#[test]
fn test_from_lowercase() {
HeaderName::from_lowercase(&[0; 10]).unwrap_err();
HeaderName::from_lowercase(&[b'A'; 10]).unwrap_err();
HeaderName::from_lowercase(&[0x1; 10]).unwrap_err();
HeaderName::from_lowercase(&[0xFF; 10]).unwrap_err();
//HeaderName::from_lowercase(&[0; 100]).unwrap_err();
HeaderName::from_lowercase(&[b'A'; 100]).unwrap_err();
HeaderName::from_lowercase(&[0x1; 100]).unwrap_err();
HeaderName::from_lowercase(&[0xFF; 100]).unwrap_err();
}
}