Merge #17229: tests: Add fuzzing harnesses for various Base{32,58,64} and hex related functions
pull/764/headc18405732e
tests: Add fuzzing harness for various hex related functions (practicalswift)526dd78bed
tests: Add fuzzing harness for various Base{32,58,64} related functions (practicalswift)32e27129ff
util: Move TrimString(...). Introduce default pattern (trims whitespace). Add NODISCARD. (practicalswift)22d9bae36f
tests: Add corpora suppression (FUZZERS_MISSING_CORPORA) for fuzzers missing in https://github.com/bitcoin-core/qa-assets/tree/master/fuzz_seed_corpus (practicalswift) Pull request description: Add fuzzing harnesses for various Base{32,58,64} and hex related functions. **Testing this PR** Run: ``` $ CC=clang CXX=clang++ ./configure --enable-fuzz \ --with-sanitizers=address,fuzzer,undefined $ make $ src/test/fuzz/base_encode_decode … $ src/test/fuzz/hex … ``` ACKs for top commit: MarcoFalke: ACKc18405732e
🔁 Tree-SHA512: 4fcbe4f641fc553e43fd5c3c40a6beec0d2ce90c5ffc718213b37fc18aba4c055e51e26f93d01ea1248fd89473d07c9dce77db7f014b47d3abd045f61b5f1905
commit
03dfa36641
@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2019 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <test/fuzz/fuzz.h>
|
||||
|
||||
#include <base58.h>
|
||||
#include <util/string.h>
|
||||
#include <util/strencodings.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
const std::string random_encoded_string(buffer.begin(), buffer.end());
|
||||
|
||||
std::vector<unsigned char> decoded;
|
||||
if (DecodeBase58(random_encoded_string, decoded, 100)) {
|
||||
const std::string encoded_string = EncodeBase58(decoded);
|
||||
assert(encoded_string == TrimString(encoded_string));
|
||||
assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string)));
|
||||
}
|
||||
|
||||
if (DecodeBase58Check(random_encoded_string, decoded, 100)) {
|
||||
const std::string encoded_string = EncodeBase58Check(decoded);
|
||||
assert(encoded_string == TrimString(encoded_string));
|
||||
assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string)));
|
||||
}
|
||||
|
||||
bool pf_invalid;
|
||||
std::string decoded_string = DecodeBase32(random_encoded_string, &pf_invalid);
|
||||
if (!pf_invalid) {
|
||||
const std::string encoded_string = EncodeBase32(decoded_string);
|
||||
assert(encoded_string == TrimString(encoded_string));
|
||||
assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string)));
|
||||
}
|
||||
|
||||
decoded_string = DecodeBase64(random_encoded_string, &pf_invalid);
|
||||
if (!pf_invalid) {
|
||||
const std::string encoded_string = EncodeBase64(decoded_string);
|
||||
assert(encoded_string == TrimString(encoded_string));
|
||||
assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string)));
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2019 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <test/fuzz/fuzz.h>
|
||||
|
||||
#include <util/strencodings.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
const std::string random_hex_string(buffer.begin(), buffer.end());
|
||||
const std::vector<unsigned char> data = ParseHex(random_hex_string);
|
||||
const std::string hex_data = HexStr(data);
|
||||
if (IsHex(random_hex_string)) {
|
||||
assert(ToLower(random_hex_string) == hex_data);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue