mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-16 18:56:54 +02:00
add the fuzzer from oss-fuzz and a test that exercises it
This commit is contained in:
21
fuzz/unpack_pack_fuzzer.cc
Normal file
21
fuzz/unpack_pack_fuzzer.cc
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <msgpack.hpp>
|
||||
|
||||
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<const char *>(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;
|
||||
}
|
@@ -37,6 +37,9 @@ LIST (APPEND check_PROGRAMS
|
||||
version.cpp
|
||||
visitor.cpp
|
||||
zone.cpp
|
||||
|
||||
# fuzzer tests
|
||||
fuzz_unpack_pack_fuzzer.cpp
|
||||
)
|
||||
|
||||
IF (MSGPACK_BOOST)
|
||||
|
10
test/fuzz_unpack_pack_fuzzer.cpp
Normal file
10
test/fuzz_unpack_pack_fuzzer.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#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));
|
||||
}
|
Reference in New Issue
Block a user