diff --git a/lib/Crypt/Misc.pm b/lib/Crypt/Misc.pm index 0782e73..79951bd 100644 --- a/lib/Crypt/Misc.pm +++ b/lib/Crypt/Misc.pm @@ -64,7 +64,7 @@ my $default = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv"; if (defined $alphabet) { - return undef if $alphabet !~ /^[a-zA-Z0-9]{58}$/; + return undef if $alphabet !~ /^[a-zA-Z0-9]{58}$/ || $base58 !~ /^[$alphabet]+$/; eval "\$base58 =~ tr/$alphabet/$default/"; # HACK: https://stackoverflow.com/questions/11415045/using-a-char-variable-in-tr return undef if $@; } diff --git a/t/crypt-misc.t b/t/crypt-misc.t index 9cd323d..d8892f3 100644 --- a/t/crypt-misc.t +++ b/t/crypt-misc.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 679; +use Test::More tests => 680; use Crypt::Misc qw( encode_b64 decode_b64 encode_b64u decode_b64u @@ -143,3 +143,5 @@ is(unpack("H*", decode_b32z(encode_b32z($b))), $h); is(unpack("H*", decode_b32c(encode_b32c($b))), $h); } + +is(decode_b58b("111OIl0"), undef, "bug: decode_b58b + invalid input");