fix: add buffer verification in GenTextFile to prevent OOB heap reads#9102
Open
Ashutosh0x wants to merge 1 commit into
Open
fix: add buffer verification in GenTextFile to prevent OOB heap reads#9102Ashutosh0x wants to merge 1 commit into
Ashutosh0x wants to merge 1 commit into
Conversation
GenTextFile() passes the buffer to GenText() without verification. A corrupted vector length causes unbounded OOB heap reads in release builds where FLATBUFFERS_ASSERT is stripped. Add Verifier check before text generation to reject corrupt buffers. Fixes google#9051
Author
|
Hi @dbaileychess — Requesting review on this security fix. It adds flatbuffers::Verifier buffer check in GenTextFile() to prevent OOB heap reads from crafted binaries. Related to issue #9051. Thanks! |
Author
|
Friendly ping @jtdavis777 @dbaileychess — this is a security fix for #9051 (OOB heap read in |
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 #9051
Summary
GenTextFile()passes the internal buffer toGenText()without running theVerifierfirst. When a binary FlatBuffer has a corrupted vector length field,GenText()iterates past the buffer boundary, causing heap-buffer-overflow reads in release builds (whereFLATBUFFERS_ASSERTis stripped).This is exploitable:
flatc --json schema.fbs -- corrupt.binsilently reads and outputs heap memory as JSON array elements, constituting information disclosure (CWE-125).Root Cause
Vector::Get()usesFLATBUFFERS_ASSERTfor bounds checking, which is a no-op in release builds. TheGenText()path trusts the vector length from the buffer without verification, unlike the FlexBuffers path which callsVerifyBuffer()inflatc.cpp.Fix
Add
Verifiercheck inGenTextFile()before callingGenText(). This is consistent with how the FlexBuffers path already verifies buffers beforeToString(). The verifier rejects corrupt buffers with an error message rather than silently reading OOB memory.Testing
The fix can be verified with the PoC from #9051:
flatc -b schema.fbs valid.jsonflatc --json schema.fbs -- corrupt.binnow returns an error instead of leaking heap contents