Skip to content

Fix heap buffer overflow in StructDef Deserialize#8954

Open
ShangzhiXu wants to merge 1 commit intogoogle:masterfrom
ShangzhiXu:fix-idl-parser-heap-overflow
Open

Fix heap buffer overflow in StructDef Deserialize#8954
ShangzhiXu wants to merge 1 commit intogoogle:masterfrom
ShangzhiXu:fix-idl-parser-heap-overflow

Conversation

@ShangzhiXu
Copy link

Fixes #8932

#8932

This PR adds a bounds check in StructDef::Deserialize to prevent a heap buffer overflow when reading malformed bfbs files. If the field ID exceeds the size of the vector, it safely returns false.

Works on my machine to fix the bug

@ShangzhiXu ShangzhiXu requested a review from dbaileychess as a code owner March 6, 2026 10:11
@google-cla
Copy link

google-cla bot commented Mar 6, 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.

@github-actions github-actions bot added c++ codegen Involving generating code from schema labels Mar 6, 2026
const auto& of = *(object->fields());
auto indexes = std::vector<uoffset_t>(of.size());
for (uoffset_t i = 0; i < of.size(); i++) indexes[of.Get(i)->id()] = i;
for (uoffset_t i = 0; i < of.size(); i++)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a small optimization I would suggest -- we should read of.size() only once (before the previous line) and use the cached value.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing for of.Get(i)->id() -- we should call this only once per loop instead of twice.

@jtdavis777 jtdavis777 added the waiting-for-update This PR is waiting for a change from the author or contributors before it is ready for merge label Mar 7, 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 waiting-for-update This PR is waiting for a change from the author or contributors before it is ready for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Heap Buffer Overflow (Write) in FlatBuffers idl_parser.cpp:4132

2 participants