diff --git a/BUILD b/BUILD index 1d27b79ddc..1fbdda4e64 100644 --- a/BUILD +++ b/BUILD @@ -356,6 +356,20 @@ cc_test( ], ) +# OSS-Fuzz test +cc_binary( + name = "file_descriptor_parsenew_fuzzer", + srcs = ["tests/file_descriptor_parsenew_fuzzer.cc"], + copts = CPPOTS + ["-fsanitizer=fuzzer,address"], + deps = [ + ":descriptor_upbproto", + ":descriptor_upbreflection", + ":upb", + ":upb_pb", + ":upb_test", + ], +) + # copybara:strip_for_google3_begin upb_proto_reflection_library( name = "descriptor_upbreflection", diff --git a/tests/file_descriptor_parsenew_fuzzer.cc b/tests/file_descriptor_parsenew_fuzzer.cc new file mode 100644 index 0000000000..41664690ea --- /dev/null +++ b/tests/file_descriptor_parsenew_fuzzer.cc @@ -0,0 +1,16 @@ +#include +#include +#include + +#include "google/protobuf/descriptor.upb.h" +#include "upb/def.h" +#include "upb/msg.h" +#include "upb/upb.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + upb_strview strview = + upb_strview_make(reinterpret_cast(data), size); + upb::Arena arena; + google_protobuf_FileDescriptorProto_parsenew(strview, arena.ptr()); + return 0; +}