nit: could be more consistent by not using a global for one and a default param for the other:
(note: these diffs do not include the return true
comment made further down)
0diff --git a/src/test/fuzz/util/descriptor.cpp b/src/test/fuzz/util/descriptor.cpp
1index c2aa6d9b6a..804fd1cd33 100644
2--- a/src/test/fuzz/util/descriptor.cpp
3+++ b/src/test/fuzz/util/descriptor.cpp
4@@ -87,16 +87,13 @@ bool HasDeepDerivPath(const FuzzBufferType& buff, const int max_depth)
5 return false;
6 }
7
8-//! Maximum number of nested sub-fragments we'll allow in a descriptor.
9-constexpr int MAX_NESTED_SUBS{10'000};
10-
11-bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs)
12+bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs, const int max_nested_subs)
13 {
14 // We use a stack because there may be many nested sub-frags.
15 std::stack<int> counts;
16 for (const auto& ch: buff) {
17 // The fuzzer may generate an input with a ton of parenthesis. Rule out pathological cases.
18- if (counts.size() > MAX_NESTED_SUBS) return false;
19+ if (counts.size() > max_nested_subs) return false;
20
21 if (ch == '(') {
22 // A new fragment was opened, create a new sub-count for it and start as one since any fragment with
23diff --git a/src/test/fuzz/util/descriptor.h b/src/test/fuzz/util/descriptor.h
24index 77ebd11ebb..22205d41ab 100644
25--- a/src/test/fuzz/util/descriptor.h
26+++ b/src/test/fuzz/util/descriptor.h
27@@ -57,11 +57,14 @@ bool HasDeepDerivPath(const FuzzBufferType& buff, const int max_depth = MAX_DEPT
28
29 //! Default maximum number of sub-fragments.
30 constexpr int MAX_SUBS{1'000};
31+//! Maximum number of nested sub-fragments we'll allow in a descriptor.
32+constexpr int MAX_NESTED_SUBS{10'000};
33
34 /**
35 * Whether the buffer, if it represents a valid descriptor, contains a fragment with more
36 * sub-fragments than the given maximum.
37 */
38-bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs = MAX_SUBS);
39+bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs = MAX_SUBS,
40+ const int max_nested_subs = MAX_NESTED_SUBS);
41
42 #endif // BITCOIN_TEST_FUZZ_UTIL_DESCRIPTOR_H
Also, this raises a narrowing warning:
0 CXX test/fuzz/util/libtest_fuzz_a-descriptor.o
1test/fuzz/util/descriptor.cpp:96:27: warning: comparison of integers of different signs: 'std::stack<int>::size_type' (aka 'unsigned long') and 'const int' [-Wsign-compare]
2 if (counts.size() > max_nested_subs) return false;
3 ~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~
41 warning generated.
So using size_t
for the max values might make sense?
0diff --git a/src/test/fuzz/util/descriptor.cpp b/src/test/fuzz/util/descriptor.cpp
1index c2aa6d9b6a..e3b5218e15 100644
2--- a/src/test/fuzz/util/descriptor.cpp
3+++ b/src/test/fuzz/util/descriptor.cpp
4@@ -87,16 +87,14 @@ bool HasDeepDerivPath(const FuzzBufferType& buff, const int max_depth)
5 return false;
6 }
7
8-//! Maximum number of nested sub-fragments we'll allow in a descriptor.
9-constexpr int MAX_NESTED_SUBS{10'000};
10-
11-bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs)
12+bool HasTooManySubFrag(const FuzzBufferType& buff, const size_t max_subs,
13+ const size_t max_nested_subs)
14 {
15 // We use a stack because there may be many nested sub-frags.
16- std::stack<int> counts;
17+ std::stack<size_t> counts;
18 for (const auto& ch: buff) {
19 // The fuzzer may generate an input with a ton of parenthesis. Rule out pathological cases.
20- if (counts.size() > MAX_NESTED_SUBS) return false;
21+ if (counts.size() > max_nested_subs) return false;
22
23 if (ch == '(') {
24 // A new fragment was opened, create a new sub-count for it and start as one since any fragment with
25diff --git a/src/test/fuzz/util/descriptor.h b/src/test/fuzz/util/descriptor.h
26index 77ebd11ebb..a379883be8 100644
27--- a/src/test/fuzz/util/descriptor.h
28+++ b/src/test/fuzz/util/descriptor.h
29@@ -56,12 +56,15 @@ constexpr int MAX_DEPTH{2};
30 bool HasDeepDerivPath(const FuzzBufferType& buff, const int max_depth = MAX_DEPTH);
31
32 //! Default maximum number of sub-fragments.
33-constexpr int MAX_SUBS{1'000};
34+constexpr size_t MAX_SUBS{1'000};
35+//! Maximum number of nested sub-fragments we'll allow in a descriptor.
36+constexpr size_t MAX_NESTED_SUBS{10'000};
37
38 /**
39 * Whether the buffer, if it represents a valid descriptor, contains a fragment with more
40 * sub-fragments than the given maximum.
41 */
42-bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs = MAX_SUBS);
43+bool HasTooManySubFrag(const FuzzBufferType& buff, const size_t max_subs = MAX_SUBS,
44+ const size_t max_nested_subs = MAX_NESTED_SUBS);
45
46 #endif // BITCOIN_TEST_FUZZ_UTIL_DESCRIPTOR_H