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

Returns an Error in case of slicing non-ascii strings #599

Merged
merged 1 commit into from
Aug 4, 2020
Merged
Changes from all commits
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
6 changes: 3 additions & 3 deletions vm/address/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl FromStr for Address {
return Err(Error::InvalidLength);
}
// ensure the network character is valid before converting
let network: Network = match &addr[0..1] {
let network: Network = match addr.get(0..1).ok_or(Error::UnknownNetwork)? {
TESTNET_PREFIX => Network::Testnet,
MAINNET_PREFIX => Network::Mainnet,
_ => {
Expand All @@ -171,7 +171,7 @@ impl FromStr for Address {
};

// get protocol from second character
let protocol: Protocol = match &addr[1..2] {
let protocol: Protocol = match addr.get(1..2).ok_or(Error::UnknownProtocol)? {
"0" => Protocol::ID,
"1" => Protocol::Secp256k1,
"2" => Protocol::Actor,
Expand All @@ -182,7 +182,7 @@ impl FromStr for Address {
};

// bytes after the protocol character is the data payload of the address
let raw = &addr[2..];
let raw = addr.get(2..).ok_or(Error::InvalidPayload)?;
if protocol == Protocol::ID {
if raw.len() > 20 {
// 20 is max u64 as string
Expand Down