Skip to content

Commit

Permalink
Returns an Error in case of slicing non-ascii strings (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
neithanmo authored Aug 4, 2020
1 parent 52a5ace commit 8b0b35c
Showing 1 changed file with 3 additions and 3 deletions.
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

0 comments on commit 8b0b35c

Please sign in to comment.