mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-01 09:35:52 -05:00
fuzz: Add fuzzing for max_ret_len in DecodeBase58/DecodeBase58Check
Different values are used for max_ret_len throughout the codebase (e.g., 21, 34, 78). Theoretically, negative and zero values are also permitted. Let's stress-test those as well. Co-authored-by: brunoerg <brunoely.gc@gmail.com>
This commit is contained in:
parent
635bc58f46
commit
f919d919eb
1 changed files with 4 additions and 2 deletions
|
@ -21,10 +21,11 @@ FUZZ_TARGET(base58_encode_decode)
|
|||
{
|
||||
FuzzedDataProvider provider(buffer.data(), buffer.size());
|
||||
const std::string random_string{provider.ConsumeRandomLengthString(1000)};
|
||||
const int max_ret_len{provider.ConsumeIntegralInRange<int>(-1, 1000)};
|
||||
|
||||
// Decode/Encode roundtrip
|
||||
std::vector<unsigned char> decoded;
|
||||
if (DecodeBase58(random_string, decoded, 100)) {
|
||||
if (DecodeBase58(random_string, decoded, max_ret_len)) {
|
||||
const auto encoded_string{EncodeBase58(decoded)};
|
||||
assert(encoded_string == TrimStringView(random_string));
|
||||
assert(encoded_string.empty() || !DecodeBase58(encoded_string, decoded, provider.ConsumeIntegralInRange<int>(0, decoded.size() - 1)));
|
||||
|
@ -40,10 +41,11 @@ FUZZ_TARGET(base58check_encode_decode)
|
|||
{
|
||||
FuzzedDataProvider provider(buffer.data(), buffer.size());
|
||||
const std::string random_string{provider.ConsumeRandomLengthString(1000)};
|
||||
const int max_ret_len{provider.ConsumeIntegralInRange<int>(-1, 1000)};
|
||||
|
||||
// Decode/Encode roundtrip
|
||||
std::vector<unsigned char> decoded;
|
||||
if (DecodeBase58Check(random_string, decoded, 100)) {
|
||||
if (DecodeBase58Check(random_string, decoded, max_ret_len)) {
|
||||
const auto encoded_string{EncodeBase58Check(decoded)};
|
||||
assert(encoded_string == TrimStringView(random_string));
|
||||
assert(encoded_string.empty() || !DecodeBase58Check(encoded_string, decoded, provider.ConsumeIntegralInRange<int>(0, decoded.size() - 1)));
|
||||
|
|
Loading…
Add table
Reference in a new issue