diff options
author | Dhruv Mehta <856960+dhruv@users.noreply.github.com> | 2021-05-24 22:14:23 -0700 |
---|---|---|
committer | Dhruv Mehta <856960+dhruv@users.noreply.github.com> | 2021-05-25 08:20:43 -0700 |
commit | e33714557747dd479f123425aa2dd08d272ef377 (patch) | |
tree | a45b10677369691609e19b99297ee129f37a29d5 | |
parent | 35571d8d9ec112bd7b6741d10052dded08410c77 (diff) |
[fuzz] Occasional valid magic bytes for transport serialization test
Before commit:
Unable to deserialize : 0%
Wrong message start : ~45.62%
Header too large : ~14.5%
Wrong checksum : ~38.13%
Invalid message type : ~1.78%
304820 NEW cov: 1440 ft: 4452 corp: 92/12551b lim: 2237 exec/s: 3386 rss: 486Mb L: 47/1111 MS: 1 ChangeByte-
1416181 REDUCE cov: 1442 ft: 5681 corp: 125/59Kb lim: 4096 exec/s: 3522 rss: 535Mb L: 2164/4049 MS: 1 EraseBytes-
After commit:
Unable to deserialize : 0%
Wrong message start : ~39.6%
Header too large : ~30.85%
Wrong checksum : ~25.54%
Invalid message type : ~4.01%
302684 NEW cov: 1454 ft: 3936 corp: 84/7056b lim: 2424 exec/s: 4146 rss: 477Mb L: 65/1108 MS: 3 CopyPart-CrossOver-CMP- DE: "\x0e\x00\x00\x00"-
1383925 REDUCE cov: 1454 ft: 4828 corp: 102/14573b lim: 4096 exec/s: 3954 rss: 534Mb L: 116/4050 MS: 2 EraseBytes-ChangeByte-
-rw-r--r-- | src/test/fuzz/p2p_transport_serialization.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/test/fuzz/p2p_transport_serialization.cpp b/src/test/fuzz/p2p_transport_serialization.cpp index c29d8e7039..edee5aeef7 100644 --- a/src/test/fuzz/p2p_transport_serialization.cpp +++ b/src/test/fuzz/p2p_transport_serialization.cpp @@ -29,8 +29,24 @@ FUZZ_TARGET_INIT(p2p_transport_serialization, initialize_p2p_transport_serializa FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; auto checksum_assist = fuzzed_data_provider.ConsumeBool(); - int header_random_bytes_count = checksum_assist ? CMessageHeader::CHECKSUM_OFFSET : CMessageHeader :: HEADER_SIZE; - auto mutable_msg_bytes = fuzzed_data_provider.ConsumeBytes<uint8_t>(header_random_bytes_count); + auto magic_bytes_assist = fuzzed_data_provider.ConsumeBool(); + std::vector<uint8_t> mutable_msg_bytes; + + auto header_bytes_remaining = CMessageHeader::HEADER_SIZE; + if (magic_bytes_assist) { + auto msg_start = Params().MessageStart(); + for (size_t i = 0; i < CMessageHeader::MESSAGE_SIZE_SIZE; ++i) { + mutable_msg_bytes.push_back(msg_start[i]); + } + header_bytes_remaining -= CMessageHeader::MESSAGE_SIZE_SIZE; + } + + if (checksum_assist) { + header_bytes_remaining -= CMessageHeader::CHECKSUM_SIZE; + } + + auto header_random_bytes = fuzzed_data_provider.ConsumeBytes<uint8_t>(header_bytes_remaining); + mutable_msg_bytes.insert(mutable_msg_bytes.end(), header_random_bytes.begin(), header_random_bytes.end()); auto payload_bytes = fuzzed_data_provider.ConsumeRemainingBytes<uint8_t>(); if (checksum_assist && mutable_msg_bytes.size() == CMessageHeader::CHECKSUM_OFFSET) { |