mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-30 07:43:48 +02:00
fuzz: Reject too large descriptor leaf sizes in scriptpubkeyman target
This commit is contained in:
@@ -143,3 +143,23 @@ bool HasTooManyWrappers(std::span<const uint8_t> buff, const int max_wrappers)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HasTooLargeLeafSize(std::span<const uint8_t> buff, const uint32_t max_leaf_size)
|
||||
{
|
||||
uint32_t leaf_len{0};
|
||||
for (auto c : buff) {
|
||||
if (c == '(' || c == ')' || c == ',' || c == '{' || c == '}') {
|
||||
// Possibly start a fresh leaf, or a fresh function name (with
|
||||
// wrappers), or terminate a prior leaf.
|
||||
leaf_len = 0;
|
||||
} else {
|
||||
// Just treat everything else as a leaf. This will also reject long
|
||||
// function names, but this should be fine if the max_leaf_size is
|
||||
// set large enough.
|
||||
if (++leaf_len > max_leaf_size) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -76,4 +76,12 @@ constexpr int MAX_WRAPPERS{100};
|
||||
*/
|
||||
bool HasTooManyWrappers(std::span<const uint8_t> buff, int max_wrappers = MAX_WRAPPERS);
|
||||
|
||||
/// Default maximum leaf size. This should be large enough to cover an extended
|
||||
/// key, including paths "/", inside and outside of "[]".
|
||||
constexpr uint32_t MAX_LEAF_SIZE{200};
|
||||
|
||||
/// Whether the expanded buffer (after calling GetDescriptor() in
|
||||
/// MockedDescriptorConverter) has a leaf size too large.
|
||||
bool HasTooLargeLeafSize(std::span<const uint8_t> buff, uint32_t max_leaf_size = MAX_LEAF_SIZE);
|
||||
|
||||
#endif // BITCOIN_TEST_FUZZ_UTIL_DESCRIPTOR_H
|
||||
|
||||
Reference in New Issue
Block a user