fix: guard against null struct_def in IsStruct/Deserialize (fixes #9144)#9148
Open
Ashutosh0x wants to merge 3 commits into
Open
fix: guard against null struct_def in IsStruct/Deserialize (fixes #9144)#9148Ashutosh0x wants to merge 3 commits into
Ashutosh0x wants to merge 3 commits into
Conversation
Add bounds checking and null validation when deserializing .bfbs files: - Null-check object->fields() before dereferencing - Detect duplicate field IDs to prevent silent overwrites - Null-check individual field pointers in the loop - Null-check enum values() and included_filenames() pointers These checks prevent heap buffer overflow via maliciously crafted .bfbs files where field IDs exceed the fields array size. Fixes google#8932
GenText/GenTextFile trusts serialized field offsets and vector lengths without running the buffer through flatbuffers::Verifier first. A malformed binary with a corrupted vector length causes flatc --json to read past the buffer allocation, leaking heap contents into the JSON output or crashing with SIGSEGV. Add a Verifier check before buffer traversal in GenTextFile. If the buffer fails verification, return an error instead of proceeding with potentially dangerous reads. Fixes google#9051
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9144
Problem
StructDef::Deserialize crashes with SEGV when deserializing a bfbs schema that passes VerifySchemaBuffer but has unresolved struct cross-references. IsStruct(), IsIncompleteStruct(), and IsTable() all dereference ype.struct_def without null check.
Root Cause
VerifySchemaBuffer validates FlatBuffer table/vtable structure but not the schema cross-references that Deserialize depends on. A field declared as BASE_TYPE_STRUCT can have a null struct_def, which IsStruct() dereferences unconditionally at idl.h:533:
cpp inline bool IsStruct(const Type& type) { return type.base_type == BASE_TYPE_STRUCT && type.struct_def->fixed; // ^^ NULL DEREF }The crash path: Parser::Deserialize -> StructDef::Deserialize -> InlineSize -> IsStruct -> SEGV.
Fix
StructDef::DeserializeviaIsStructon a bfbs schema that passesVerifySchemaBuffer#9144Testing
Impact
Any application following the recommended 'verify before use' pattern (VerifySchemaBuffer + Deserialize) is vulnerable to DoS via crafted bfbs schema input.