[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:
coder7695
2025-11-27 16:52:28 +01:00
committed by GitHub
parent 84f4b83d3e
commit 2b107e20c5
13 changed files with 495 additions and 10 deletions

View File

@@ -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;
}