From 855b377d513b793a96a52c21f728cd9ebf76c4b4 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 20 Mar 2018 15:37:08 -0400 Subject: [PATCH] Fix crash in Address::from_str if input isn't long enough --- src/util/address.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/address.rs b/src/util/address.rs index d4efde07..95cf6e24 100644 --- a/src/util/address.rs +++ b/src/util/address.rs @@ -241,8 +241,9 @@ impl FromStr for Address { fn from_str(s: &str) -> Result { // bech32 (note that upper or lowercase is allowed but NOT mixed case) - if &s.as_bytes()[0..3] == b"bc1" || &s.as_bytes()[0..3] == b"tb1" || - &s.as_bytes()[0..3] == b"BC1" || &s.as_bytes()[0..3] == b"TB1" { + if s.len() >= 3 && + (&s.as_bytes()[0..3] == b"bc1" || &s.as_bytes()[0..3] == b"tb1" || + &s.as_bytes()[0..3] == b"BC1" || &s.as_bytes()[0..3] == b"TB1") { let witprog = try!(WitnessProgram::from_address(s)); let network = match witprog.network() { bitcoin_bech32::constants::Network::Bitcoin => Network::Bitcoin,