Skip to content

Commit 4a8181b

Browse files
tests: Add std::vector<uint8_t> ConsumeFixedLengthByteVector(FuzzedDataProvider& fuzzed_data_provider, const size_t length)
1 parent 45a6811 commit 4a8181b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/test/fuzz/util.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,18 @@ NODISCARD inline bool ContainsSpentInput(const CTransaction& tx, const CCoinsVie
214214
return false;
215215
}
216216

217+
/**
218+
* Returns a byte vector of specified size regardless of the number of remaining bytes available
219+
* from the fuzzer. Pads with zero value bytes if needed to achieve the specified size.
220+
*/
221+
NODISCARD inline std::vector<uint8_t> ConsumeFixedLengthByteVector(FuzzedDataProvider& fuzzed_data_provider, const size_t length) noexcept
222+
{
223+
std::vector<uint8_t> result(length);
224+
const std::vector<uint8_t> random_bytes = fuzzed_data_provider.ConsumeBytes<uint8_t>(length);
225+
if (!random_bytes.empty()) {
226+
std::memcpy(result.data(), random_bytes.data(), random_bytes.size());
227+
}
228+
return result;
229+
}
230+
217231
#endif // BITCOIN_TEST_FUZZ_UTIL_H

0 commit comments

Comments
 (0)