Skip to content

Fix out-of-bounds vector access in StructDef::Deserialize#8988

Open
Noamismach wants to merge 3 commits intogoogle:masterfrom
Noamismach:patch-1
Open

Fix out-of-bounds vector access in StructDef::Deserialize#8988
Noamismach wants to merge 3 commits intogoogle:masterfrom
Noamismach:patch-1

Conversation

@Noamismach
Copy link

Description:
When parsing a binary schema (.bfbs), StructDef::Deserialize allocates the indexes vector based on the number of fields (of.size()). However, it directly uses the parsed id() as the index for assignment without validating if the id is within the allocated bounds.

If a schema contains a field with an id that is greater than or equal to the total number of fields, this results in an out-of-bounds vector write, causing memory corruption or a crash (e.g., catching a heap-buffer-overflow with AddressSanitizer).

This PR adds a simple bounds check to ensure the field_id is strictly less than of.size() before writing to the indexes vector, safely aborting the deserialization if the schema is malformed.

Testing:

  • Verified that valid schemas continue to deserialize correctly.
  • Confirmed that a malformed schema with an oversized field ID now gracefully returns an error instead of causing an OOB write.

@github-actions github-actions bot added c++ codegen Involving generating code from schema labels Mar 19, 2026
@google-cla
Copy link

google-cla bot commented Mar 19, 2026

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.

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.

1 participant