Repository navigation
Conversation
All existing fuzz targets live in tests/fuzzer/ and are C++, so the Rust runtime (rust/flatbuffers) had no fuzzing coverage at all. Its flatbuffers::root::<T>() entry point promises that any buffer it accepts can be read through the safe accessor API without out-of-bounds accesses, but nothing was checking that promise. Add a cargo-fuzz target next to the crate it tests. It feeds arbitrary bytes to root::<T>() (plain and size-prefixed) and, whenever verification succeeds, reads the result back exclusively through the safe API: the generated Monster accessors, the union accessors and the public Table/VTable methods. A hole in the verifier therefore surfaces as a panic or an AddressSanitizer report. Requested for the project repository in google/oss-fuzz#16202.
|
This is the in-repo companion to #9290: a fuzz target that exercises the Rust verifier plus the public safe reader path ( Scope is deliberately narrow — 3 new files, +192/−0, no library changes: It has never had a maintainer's opinion. If adding a |
Summary
The Rust runtime (
rust/flatbuffers) has no fuzz coverage. All eight fuzz targets live intests/fuzzer/and are C++ (verifier_fuzzer,scalar_fuzzer,parser_fuzzer, ...); there is nocargo-fuzztarget anywhere in the tree. As a result the Rust safe reader path is not fuzzed even though it is the one that makes a promise: anything returned byflatbuffers::root::<T>()must be readable through the safe accessors without out-of-bounds accesses.OSS-Fuzz policy is that fuzz targets belong in the project repository, and the OSS-Fuzz maintainer asked for exactly this in google/oss-fuzz#16202:
What this adds
A
cargo-fuzztarget,rust_verifier, thatflatbuffers::root::<Monster>()andflatbuffers::size_prefixed_root::<Monster>()(the C++verifier_fuzzerchecks both root forms too);unsafe) API: the generatedMonsteraccessors, the union accessors, and the publicTable/VTablemethods.Any hole in the Rust verifier therefore shows up as a panic or an AddressSanitizer report instead of as silent memory corruption in a downstream user's program.
Layout
It is a standard
cargo-fuzzproject (the layout required by the OSS-Fuzz Rust guide):It lives next to the crate it tests (
rust/flatbuffers), which is wherecargo fuzz initputs thefuzz/directory, and it can be wired into OSS-Fuzz with:The target reuses the schema-generated types that the Rust test-suite already checks in (
tests/monster_test/mod.rs), i.e. exactly the codeflatcemits for users, so no new schema or generated code is added.Build and run
cd rust/flatbuffers cargo +nightly fuzz build rust_verifier cargo +nightly fuzz run rust_verifier fuzz/corpus/rust_verifierA valid seed (e.g.
tests/monsterdata_test.mon) runs clean.Relation to the verifier fix
#9290 hardens exactly the paths this target exercises: it rejects degenerate vtables (
vtable_len < 2 * SIZE_VOFFSET) inVerifier::visit_table, and makes the Rust generator verify union values whose discriminant is unknown instead of accepting them unchecked (_ => Ok(())). On the currentmasterruntime this target already reproduces a crash: a buffer whose root table passesflatbuffers::root::<Monster>()while carrying an unknown union discriminant hands the reader an unverified union table, and the safeVTableAPI then reads past the end of the buffer. That is the class of bug the target is meant to catch, and it goes away once #9290 is in and the generated code is regenerated with the fixed generator.cc @dbaileychess