mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-12 07:50:59 +00:00
[fuzzer] Adds code generation target. (#8795)
* adds code generation fuzzer target. * add buffer verification * add table verification in codegen fuzzer --------- Co-authored-by: Björn Harrtell <bjornharrtell@users.noreply.github.com>
This commit is contained in:
@@ -45,13 +45,20 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
auto parse_input = input.c_str();
|
||||
|
||||
// Check Parser.
|
||||
parser.Parse(parse_input);
|
||||
// TODO:
|
||||
// Need to add additional checks for inputs passed Parse(parse_input)
|
||||
// successfully:
|
||||
// 1. Serialization to bfbs.
|
||||
// 2. Generation of a default object.
|
||||
// 3. Verification of the object using reflection.
|
||||
// 3. Printing to json.
|
||||
auto result = parser.Parse(parse_input);
|
||||
if (result) {
|
||||
parser.Serialize();
|
||||
const uint8_t* buf = parser.builder_.GetBufferPointer();
|
||||
flatbuffers::Verifier verifier(buf, parser.builder_.GetSize());
|
||||
TEST_EQ(true, reflection::VerifySchemaBuffer(verifier));
|
||||
|
||||
auto root = flatbuffers::GetRoot<flatbuffers::Table>(buf);
|
||||
if (verifier.VerifyTableStart(buf) && root->VerifyTableStart(verifier)) {
|
||||
if (parser.root_struct_def_) {
|
||||
std::string json_output;
|
||||
flatbuffers::GenText(parser, buf, &json_output);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user