diff --git a/fuzz/unpack_pack_fuzzer.cc b/fuzz/unpack_pack_fuzzer.cc new file mode 100644 index 00000000..7f967331 --- /dev/null +++ b/fuzz/unpack_pack_fuzzer.cc @@ -0,0 +1,21 @@ +#include + +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 = 10000; + msgpack::object_handle unpacked = msgpack::unpack(reinterpret_cast(data), + size, + nullptr, + nullptr, + msgpack::unpack_limit(test_limit, + test_limit, + test_limit, + test_limit)); + msgpack::sbuffer sbuf; + msgpack::pack(sbuf, unpacked.get()); + } catch (...) { + } + return 0; +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 89c6f97a..e19c5d67 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -37,6 +37,9 @@ LIST (APPEND check_PROGRAMS version.cpp visitor.cpp zone.cpp + + # fuzzer tests + fuzz_unpack_pack_fuzzer.cpp ) IF (MSGPACK_BOOST) diff --git a/test/fuzz_unpack_pack_fuzzer.cpp b/test/fuzz_unpack_pack_fuzzer.cpp new file mode 100644 index 00000000..56fb28f9 --- /dev/null +++ b/test/fuzz_unpack_pack_fuzzer.cpp @@ -0,0 +1,10 @@ +#include + +#include "../fuzz/unpack_pack_fuzzer.cc" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); + +TEST(FUZZ_UNPACK_PACK_FUZZER, works) +{ + EXPECT_EQ(0, LLVMFuzzerTestOneInput(0, 0)); +}