From 51bd6923926551b0795f2f43813fe629f793095a Mon Sep 17 00:00:00 2001 From: tuxmain Date: Tue, 8 Dec 2020 21:12:02 +0100 Subject: [PATCH] Limit pubkey to 43-44 chars --- src/utils.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils.rs b/src/utils.rs index 105c488..91e1c56 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -10,8 +10,12 @@ pub enum PubkeyDecodeError { /// Accepts any checksum length >=3 pub fn format_pubkey(raw: &str) -> Result { let mut iter = raw.splitn(2, ':'); + let raw_pubkey = iter.next().ok_or(PubkeyDecodeError::BadFormat)?; + if raw_pubkey.len() < 43 || raw_pubkey.len() > 44 { + return Err(PubkeyDecodeError::BadFormat); + } let mut pubkey = [0u8; 32]; - bs58::decode(iter.next().ok_or(PubkeyDecodeError::BadFormat)?) + bs58::decode(raw_pubkey) .into(&mut pubkey) .map_err(|_| PubkeyDecodeError::BadFormat)?;