From e2403a37fabf663581fdda421cb449d4b941e518 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 14 May 2018 11:07:30 -0400 Subject: [PATCH] Don't try to do a base58 checksum if an address is excessively long --- src/util/address.rs | 4 ++++ src/util/base58.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/util/address.rs b/src/util/address.rs index 95cf6e24..80d9660d 100644 --- a/src/util/address.rs +++ b/src/util/address.rs @@ -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)); diff --git a/src/util/base58.rs b/src/util/base58.rs index 91badc9d..5162edc3 100644 --- a/src/util/base58.rs +++ b/src/util/base58.rs @@ -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),