1 #include <stdlib.h> 2 #include <stdint.h> 3 #include <string.h> 4 #include <string> 5 #include <sstream> 6 #include <fstream> 7 #include "dgif_fuzz_common.h" 8 9 #include "libprotobuf-mutator/src/libfuzzer/libfuzzer_macro.h" 10 #include "ProtoToGif.h" 11 12 using namespace gifProtoFuzzer; 13 DEFINE_PROTO_FUZZER(const GifProto & gif_proto)14DEFINE_PROTO_FUZZER(const GifProto &gif_proto) 15 { 16 // Instantiate ProtoConverter object 17 ProtoConverter converter; 18 std::string gifRawData = converter.gifProtoToString(gif_proto); 19 if (const char *dump_path = getenv("PROTO_FUZZER_DUMP_PATH")) 20 { 21 // With libFuzzer binary run this to generate a GIF from proto: 22 // PROTO_FUZZER_DUMP_PATH=x.gif ./fuzzer proto-input 23 std::ofstream of(dump_path); 24 of.write(gifRawData.data(), gifRawData.size()); 25 } 26 fuzz_dgif_extended((const uint8_t *)gifRawData.data(), gifRawData.size()); 27 }