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

Add fuzz testing harness to smithy-json and fix bug found by it #462

Merged
merged 4 commits into from
Jun 4, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions rust-runtime/smithy-json/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,11 @@ fn read_codepoint(rest: &[u8]) -> Result<u16, Error> {
let codepoint_str = std::str::from_utf8(&rest[2..6]).map_err(|_| Error::InvalidUtf8)?;

// Error on characters `u16::from_str_radix` would otherwise accept, such as `+`
if codepoint_str.bytes().any(|byte| !matches!(byte, b'0'..=b'9' | b'a'..=b'f' | b'A'..=b'F')) {
return Err(Error::InvalidUnicodeEscape(codepoint_str.into()))
if codepoint_str
.bytes()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, I was going to suggest this, great minds :-)

.any(|byte| !matches!(byte, b'0'..=b'9' | b'a'..=b'f' | b'A'..=b'F'))
{
return Err(Error::InvalidUnicodeEscape(codepoint_str.into()));
}
Ok(u16::from_str_radix(codepoint_str, 16).expect("hex string is valid 16-bit value"))
}
Expand Down