Skip to content

flexbuffers: reject self-referencing vectors when a reuse tracker is used - #9440

Open
vivek7424 wants to merge 1 commit into
google:masterfrom
vivek7424:fix-flexbuffers-cycle-reuse-tracker
Open

vivek7424 wants to merge 1 commit into
google:masterfrom
vivek7424:fix-flexbuffers-cycle-reuse-tracker

Conversation

@vivek7424

@vivek7424 vivek7424 commented Oct 28, 2026 •

Copy link
Copy Markdown

Summary

With a reuse tracker, flexbuffers::VerifyBuffer marks a vector as verified before it checks that vector's elements. An element that refers back to the vector finds the mark and is accepted, so a cyclic vector verifies. A consumer that walks the data recursively, such as Reference::ToString (used by flatc --json --flexbuffers), then recurses without bound and overflows the stack.

This PR marks the vector as in progress while its elements are checked. An element that reaches an in-progress vector fails verification. Shared, non-cyclic vectors still short-circuit as before.

Reproduction

The 31-byte input from #9074:

76 65 63 65 46 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 62 6f 6f 6c 73 00 04 01 00 28 01

Before this change:

  • VerifyBuffer with a reuse tracker returns true. Walking the first element reaches depth 300 on a 31-byte buffer, which is only possible through a cycle.
  • VerifyBuffer without a tracker returns false.
  • flatc --json --flexbuffers on this file segfaults, with ToString and AppendToString<Vector> repeating in the backtrace.

After this change, all three reject the input.

Tests

FlexBuffersCycleRejectedTest checks that these bytes fail to verify with and without a tracker. The unpatched tree fails this test at flexbuffers_test.cpp:330. With this change, the full flattests suite passes.

Notes

@google-cla

google-cla Bot commented Oct 28, 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.

…used

With a reuse tracker, VerifyVector marked a vector as verified before checking
its elements. An element that referred back to the vector was accepted, so a
cyclic vector verified and recursive consumers (Reference::ToString, used by
flatc --json --flexbuffers) overflowed the stack.

Mark the vector as in progress while its elements are checked, and fail if an
in-progress vector is reached again. Shared, non-cyclic vectors still
short-circuit as before.
@vivek7424
vivek7424 force-pushed the fix-flexbuffers-cycle-reuse-tracker branch from 46e0b7b to 57dbe30 Compare October 28, 2026 02:39

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant