Coverage Report

Created: 2023-09-25 06:13

/src/msgpack-c/fuzz/unpack_pack_fuzzer.cpp
Line
Count
Source
1
#include <msgpack.hpp>
2
3
// The function's signature must NOT be changed since other projects rely on it:
4
// - libFuzzer
5
// - AFL++
6
// - Google's oss-fuzz (uses the previous two ones)
7
2.25k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
8
2.25k
  try {
9
    // NOTE(derwolfe): by default the limits are set at 2^32-1 length. I'm
10
    // setting these at far smaller values to avoid OOMs
11
2.25k
    const int test_limit = 1000;
12
2.25k
    msgpack::object_handle unpacked = msgpack::unpack(reinterpret_cast<const char *>(data),
13
2.25k
                                                      size,
14
2.25k
                                                      MSGPACK_NULLPTR,
15
2.25k
                                                      MSGPACK_NULLPTR,
16
2.25k
                                                      msgpack::unpack_limit(test_limit,
17
2.25k
                                                                            test_limit,
18
2.25k
                                                                            test_limit,
19
2.25k
                                                                            test_limit,
20
2.25k
                                                                            test_limit,
21
2.25k
                                                                            test_limit));
22
2.25k
    msgpack::sbuffer sbuf;
23
2.25k
    msgpack::pack(sbuf, unpacked.get());
24
2.25k
  } catch (...) {
25
1.05k
  }
26
2.25k
  return 0;
27
2.25k
}