close
Skip to content

Security: Add buffer verification in GenTextFile to prevent OOB heap reads#9121

Open
Ashutosh0x wants to merge 2 commits into
google:masterfrom
Ashutosh0x:fix/gentext-verify-buffer
Open

Security: Add buffer verification in GenTextFile to prevent OOB heap reads#9121
Ashutosh0x wants to merge 2 commits into
google:masterfrom
Ashutosh0x:fix/gentext-verify-buffer

Conversation

@Ashutosh0x
Copy link
Copy Markdown

@Ashutosh0x Ashutosh0x commented Jun 3, 2026

Summary

Fix out-of-bounds heap read in flatc --json by adding Verifier check before buffer traversal in GenTextFile.

Vulnerability (#9051)

GenText()/GenTextFile() trusts serialized vector length fields without running the buffer through flatbuffers::Verifier. A malformed binary with a corrupted vector length causes flatc --json to read past the buffer allocation, leaking heap contents into JSON output or crashing with SIGSEGV.

Fix

Add flatbuffers::Verifier check in GenTextFile() before calling GenText(). If verification fails, return an error instead of proceeding with potentially dangerous reads.

Fixes #9051

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
@Ashutosh0x Ashutosh0x requested a review from dbaileychess as a code owner June 3, 2026 06:58
@github-actions github-actions Bot added c++ codegen Involving generating code from schema labels Jun 3, 2026
@Ashutosh0x
Copy link
Copy Markdown
Author

Hi @dbaileychess — this adds buffer verification in GenTextFile before traversal, fixing the OOB heap read reported in #9051.

The root cause is that GenText trusts serialized vector lengths and field offsets from the binary without running the Verifier first. In release builds where FLATBUFFERS_ASSERT is stripped, a corrupted vector length causes flatc to silently read past the allocation and format heap contents as JSON — an information disclosure vector.

The fix adds a single Verifier check before buffer traversal. If verification fails, GenTextFile returns an error string instead of proceeding with unsafe reads. Happy to adjust if needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ codegen Involving generating code from schema

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Out-of-Bounds Heap Read in flatc --json

1 participant