Fix OOB panic in FlexBuffers Rust get_bool/read_usize and UAF in C++ SymbolTable::Add#9105
Open
XananasX7 wants to merge 2 commits into
Open
Conversation
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
Two unpatched memory-safety bugs in
google/flatbuffers— one in the Rust FlexBuffers reader and one in the C++ IDL parser. Both are reachable from untrusted input via the public API.Fix 1: FlexBuffers Rust — OOB panic in
get_bool()andread_usize()(fixes #8923)File:
rust/flexbuffers/src/reader/mod.rsget_bool()at line 326 uses a direct unchecked slice index:When
self.address + self.width.n_bytes()exceedsself.buffer.len(), this panics with an index-out-of-bounds. The 4-byte payload[0x5d, 0x79, 0x6b, 0x02]reliably triggers this panic.Similarly,
read_usize()uses&buffer[address..](panics if address >= buffer.len()) andcursor[0](panics on empty slice) for W8 widths.All other numeric accessors (
get_u64, etc.) already use.get()with proper error propagation —get_boolandread_usizeare the only stragglers.Fix: Replace direct indexing with
.get()+.ok_or(Error::FlexbufferOutOfBounds)?/.unwrap_or_default(), matching the existing pattern in the same file.Fix 2: C++ IDL — Use-after-free / double-free in
SymbolTable::Add()via duplicate enum/table handling (fixes #9009)File:
include/flatbuffers/idl.hSymbolTable::Add()callsvec.emplace_back(e)before checking for duplicate names:When a duplicate is found, the caller (
idl_parser.cpp) deletese, but the pointer remains invec. The destructor~SymbolTable()later iteratesvecanddeletes every entry, hitting the already-freed pointer — use-after-free / double-free.Triggerable via
Parser::Deserialize()with a crafted 176-byte.bfbsschema containing a duplicate enum name. A proof-of-concept base64 payload is provided in issue #9009.Fix: Reorder the duplicate check before
vec.emplace_back(e). The pointer is only added tovecif it is not a duplicate, ensuring~SymbolTable()never frees a pointer that the caller already deleted.Both fixes are minimal single-location changes that match the existing style and defensive patterns in the codebase.