Don't try to do a base58 checksum if an address is excessively long

This commit is contained in:
Matt Corallo 2018-05-14 11:07:30 -04:00
parent dab2f0b6b6
commit e2403a37fa
2 changed files with 6 additions and 0 deletions

View File

@ -259,6 +259,10 @@ impl FromStr for Address {
});
}
if s.len() > 50 {
return Err(Error::Base58(base58::Error::InvalidLength(s.len() * 11 / 15)));
}
// Base 58
let data = try!(base58::from_check(s));

View File

@ -27,6 +27,8 @@ pub enum Error {
/// Checksum was not correct (expected, actual)
BadChecksum(u32, u32),
/// The length (in bytes) of the object was not correct
/// Note that if the length is excessively long the provided length may be
/// an estimate (and the checksum step may be skipped).
InvalidLength(usize),
/// Version byte(s) were not recognized
InvalidVersion(Vec<u8>),