MCPcopy Create free account
hub / github.com/ElementsProject/elements / FUZZ_TARGET

Function FUZZ_TARGET

src/test/fuzz/asmap_direct.cpp:15–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13#include <assert.h>
14
15FUZZ_TARGET(asmap_direct)
16{
17 // Encoding: [asmap using 1 bit / byte] 0xFF [addr using 1 bit / byte]
18 std::optional<size_t> sep_pos_opt;
19 for (size_t pos = 0; pos < buffer.size(); ++pos) {
20 uint8_t x = buffer[pos];
21 if ((x & 0xFE) == 0) continue;
22 if (x == 0xFF) {
23 if (sep_pos_opt) return;
24 sep_pos_opt = pos;
25 } else {
26 return;
27 }
28 }
29 if (!sep_pos_opt) return; // Needs exactly 1 separator
30 const size_t sep_pos{sep_pos_opt.value()};
31 if (buffer.size() - sep_pos - 1 > 128) return; // At most 128 bits in IP address
32
33 // Checks on asmap
34 std::vector<bool> asmap(buffer.begin(), buffer.begin() + sep_pos);
35 if (SanityCheckASMap(asmap, buffer.size() - 1 - sep_pos)) {
36 // Verify that for valid asmaps, no prefix (except up to 7 zero padding bits) is valid.
37 std::vector<bool> asmap_prefix = asmap;
38 while (!asmap_prefix.empty() && asmap_prefix.size() + 7 > asmap.size() && asmap_prefix.back() == false) {
39 asmap_prefix.pop_back();
40 }
41 while (!asmap_prefix.empty()) {
42 asmap_prefix.pop_back();
43 assert(!SanityCheckASMap(asmap_prefix, buffer.size() - 1 - sep_pos));
44 }
45 // No address input should trigger assertions in interpreter
46 std::vector<bool> addr(buffer.begin() + sep_pos + 1, buffer.end());
47 (void)Interpret(asmap, addr);
48 }
49}

Callers

nothing calls this directly

Calls 8

SanityCheckASMapFunction · 0.85
InterpretFunction · 0.85
sizeMethod · 0.45
valueMethod · 0.45
beginMethod · 0.45
emptyMethod · 0.45
pop_backMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected