Fix out-of-bounds write in BFBS field iteration - #9203
Conversation
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.
|
Verified the regression path locally. On PR head cmake -S . -B build-review-9203-a -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_BUILD_CPP17=ON
cmake --build build-review-9203-a --target flattests -j$(nproc)
./build-review-9203-a/flattests
cmake -S . -B build-review-9203-assert -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_CXX_FLAGS="-D_GLIBCXX_ASSERTIONS"
cmake --build build-review-9203-assert --target flattests -j$(nproc)
./build-review-9203-assert/flattestsThen I checked out the parent I also grepped the tree for the same direct I did not run the full multi-language Tried to submit this as an approving review, but GitHub rejects formal PR reviews here for accounts without explicit repository access, so leaving the verified result as a comment. |
Summary
ForAllFieldsimplementation inBaseBfbsGeneratorProblem
ForAllFieldsallocated a vector withobject->fields()->size()entries andthen used
field->id()as the write index. A structurally valid BFBS can containa 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
BaseBfbsGeneratoris removed in favor of the centralized helper.Testing
VerifySchemaBufferALL TESTS PASSEDFixes #8950