Fix heap buffer overflow in StructDef::Deserialize (.bfbs files)#9115
Open
Ashutosh0x wants to merge 1 commit into
Open
Fix heap buffer overflow in StructDef::Deserialize (.bfbs files)#9115Ashutosh0x wants to merge 1 commit into
Ashutosh0x wants to merge 1 commit 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
Author
|
@dbaileychess Hi! This PR fixes the heap buffer overflow in
All CI checks are green (6/6 passed). CLA is signed. The change is +30/-8 lines in a single file ( Could you please review? This is a supply-chain-relevant vulnerability since |
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.
Summary
Fix for #8932 - Add comprehensive bounds checking, null validation, and duplicate field ID detection when deserializing
.bfbs(binary schema) files.Problem
StructDef::Deserializeinidl_parser.cppreads field IDs from user-provided.bfbsfiles and uses them as array indices without adequate validation. This enables a heap buffer overflow of up to 262,140 bytes via crafted.bfbsfiles.Vulnerabilities Fixed
object->fields()dereferenced without null check (line 4133)_enum->values()dereferenced without null checks->included_filenames()dereferenced without null checkSupply Chain Impact
FlatBuffers is used by Google, Facebook, Microsoft, and Netflix.
.bfbsfiles are shared via schema registries and processed automatically in CI/CD pipelines. A malicious.bfbsfile uploaded to a shared registry could execute arbitrary code on every downstream build system.Fix
object->fields()before dereferencingfield_countvariable to avoid repeated calls toof.size()id_usedvector to detect duplicate field IDs_enum->values()inEnumDef::Deserializes->included_filenames()inParser::DeserializeTesting
The fix adds defensive checks that reject malformed
.bfbsinput with clear error messages. Normal valid.bfbsfiles are unaffected.Fixes #8932