Skip to content

reflection: bounds check field->id() in ForAllFields and FieldIdToIndex - #9445

Open
siddiqueirshad wants to merge 1 commit into
google:masterfrom
siddiqueirshad:fix/reflection-field-id-bounds-check
Open

siddiqueirshad wants to merge 1 commit into
google:masterfrom
siddiqueirshad:fix/reflection-field-id-bounds-check

Conversation

@siddiqueirshad

Copy link
Copy Markdown

Description

Bounds-check \ ield->id() < field_to_id_map.size()\ before writing into the field-id-to-index mapping in:

  • \src/reflection.cpp\ (\ForAllFields)
  • \src/bfbs_gen.h\ (\FieldIdToIndex)

Fixes #9426.

Motivation

\ForAllFields()\ and \FieldIdToIndex()\ build a field-id-to-index table by writing \ ield_to_id_map[field->id()], where the vector is sized to \object->fields()->size(). If a schema buffer has a field whose \id()\ exceeds \ ields()->size(), direct array subscripting triggers an out-of-bounds heap write. Adding a bounds check ensures safe indexing without writing past the allocation.

Check that field->id() is within vector bounds before indexing in
ForAllFields and FieldIdToIndex to prevent heap out-of-bounds writes
when processing schema buffers where field->id() exceeds the field count.

Fixes google#9426

Signed-off-by: siddiqui irshad <mohdirshad1306@gmail.com>
@google-cla

google-cla Bot commented Oct 29, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added c++ codegen Involving generating code from schema labels Oct 29, 2026

This branch has not been deployed

No deployments
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.

reflection: ForAllFields writes out of bounds when field->id() exceeds fields()->size()

1 participant