Skip to content

Commit 59c0ece

Browse files
committed
fuzz: replace hardcoded numbers for bech32 limits
Use bech32::CharLimit::BECH32 and bech32::CHECKSUM_SIZE instead of hardcoded values. This is a follow-up fix for #34007 (where this file was missed)
1 parent 949b673 commit 59c0ece

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/bech32.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ namespace
1919

2020
typedef std::vector<uint8_t> data;
2121

22-
/** The Bech32 and Bech32m checksum size */
23-
constexpr size_t CHECKSUM_SIZE = 6;
24-
2522
/** The Bech32 and Bech32m character set for encoding. */
2623
const char* CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
2724

src/bech32.h

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
namespace bech32
2222
{
2323

24+
/** The Bech32 and Bech32m checksum size */
25+
constexpr size_t CHECKSUM_SIZE = 6;
26+
2427
enum class Encoding {
2528
INVALID, //!< Failed decoding
2629

src/test/fuzz/bech32.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ FUZZ_TARGET(bech32)
2929
std::vector<unsigned char> input;
3030
ConvertBits<8, 5, true>([&](unsigned char c) { input.push_back(c); }, buffer.begin(), buffer.end());
3131

32-
if (input.size() + 3 + 6 <= 90) {
33-
// If it's possible to encode input in Bech32(m) without exceeding the 90-character limit:
32+
// Input data part + 3 characters for the HRP and separator (bc1) + the checksum characters
33+
if (input.size() + 3 + bech32::CHECKSUM_SIZE <= bech32::CharLimit::BECH32) {
34+
// If it's possible to encode input in Bech32(m) without exceeding the bech32-character limit:
3435
for (auto encoding : {bech32::Encoding::BECH32, bech32::Encoding::BECH32M}) {
3536
const std::string encoded = bech32::Encode(encoding, "bc", input);
3637
assert(!encoded.empty());

0 commit comments

Comments
 (0)