From c952aaeb3ee472e3776655b8ea07299ebed702c7 Mon Sep 17 00:00:00 2001 From: justmoon Date: Tue, 17 Jul 2012 14:28:41 +0200 Subject: [PATCH] Explicit check for invalid characters in Base58 decoder. --- src/base58.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/base58.js b/src/base58.js index c64683d..9313c55 100644 --- a/src/base58.js +++ b/src/base58.js @@ -1,6 +1,7 @@ (function (Bitcoin) { Bitcoin.Base58 = { alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", + validRegex: /^[1-9A-HJ-NP-Za-km-z]+$/, base: BigInteger.valueOf(58), /** @@ -45,6 +46,9 @@ var leadingZerosNum = 0; for (var i = input.length - 1; i >= 0; i--) { var alphaIndex = B58.alphabet.indexOf(input[i]); + if (alphaIndex < 0) { + throw "Invalid character"; + } bi = bi.add(BigInteger.valueOf(alphaIndex) .multiply(B58.base.pow(input.length - 1 -i)));