File: unpack_pack_fuzzer.cpp

package info (click to toggle)
msgpack-cxx 7.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,520 kB
  • sloc: cpp: 87,413; ansic: 3,571; sh: 56; makefile: 39
file content (27 lines) | stat: -rw-r--r-- 1,358 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <msgpack.hpp>

// The function's signature must NOT be changed since other projects rely on it:
// - libFuzzer
// - AFL++
// - Google's oss-fuzz (uses the previous two ones)
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  try {
    // NOTE(derwolfe): by default the limits are set at 2^32-1 length. I'm
    // setting these at far smaller values to avoid OOMs
    const int test_limit = 1000;
    msgpack::object_handle unpacked = msgpack::unpack(reinterpret_cast<const char *>(data),
                                                      size,
                                                      MSGPACK_NULLPTR,
                                                      MSGPACK_NULLPTR,
                                                      msgpack::unpack_limit(test_limit,
                                                                            test_limit,
                                                                            test_limit,
                                                                            test_limit,
                                                                            test_limit,
                                                                            test_limit));
    msgpack::sbuffer sbuf;
    msgpack::pack(sbuf, unpacked.get());
  } catch (...) {
  }
  return 0;
}