Skip to content

Fix out-of-bounds write in BFBS field iteration - #9203

Open
maxvanamersfort wants to merge 1 commit into
google:masterfrom
maxvanamersfort:fix-bfbs-field-id-oob
Open

Fix out-of-bounds write in BFBS field iteration#9203
maxvanamersfort wants to merge 1 commit into
google:masterfrom
maxvanamersfort:fix-bfbs-field-id-oob

Conversation

@maxvanamersfort

Copy link
Copy Markdown

Summary

  • treat field IDs read from BFBS input as untrusted values
  • sort field pointers by ID instead of indexing a field-count-sized vector
  • reuse the centralized ForAllFields implementation in BaseBfbsGenerator
  • add regression coverage for a verifier-accepted BFBS containing field ID 65535

Problem

ForAllFields allocated a vector with object->fields()->size() entries and
then used field->id() as the write index. A structurally valid BFBS can contain
a sparse or oversized field ID, so processing such a schema could write past the
end of that vector.

Fix

Collect the field pointers, sort them by ID, and iterate over the sorted pointers
in forward or reverse order. This preserves the expected order for normal BFBS
schemas without assuming that IDs form a dense range. The duplicate vulnerable
mapping in BaseBfbsGenerator is removed in favor of the centralized helper.

Testing

  • reproduced the original out-of-bounds access with libstdc++ assertions enabled
  • confirmed the crafted BFBS passes VerifySchemaBuffer
  • added a regression test using field ID 65535
  • ran the full upstream C++ test suite: ALL TESTS PASSED

Fixes #8950

Treat field IDs from reflection schemas as untrusted when iterating. Sort field pointers by ID instead of indexing a field-count-sized vector, and add regression coverage for a verified BFBS containing ID 65535.
@github-actions github-actions Bot added c++ codegen Involving generating code from schema labels Aug 20, 2026
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.

Heap Out-of-Bounds Write via Unchecked field->id() Index in BFBS Schema Processing

1 participant