Skip to content

[C++] Harden FlexBuffers scalar mutation verification#9089

Open
kmackinley wants to merge 1 commit into
google:masterfrom
kmackinley:flexbuffers-mutation-hardening
Open

[C++] Harden FlexBuffers scalar mutation verification#9089
kmackinley wants to merge 1 commit into
google:masterfrom
kmackinley:flexbuffers-mutation-hardening

Conversation

@kmackinley
Copy link
Copy Markdown

Summary

  • Reject FlexBuffers indirect scalar references whose target scalar bytes overlap the offset field that points to them.
  • Make Reference::MutateBool() copy from a scalar source wide enough for forced-width bool storage.
  • Add regression coverage for overlapping indirect scalar verification and forced-width bool mutation.

Motivation

FlexBuffers scalar mutation assumes the resolved scalar storage is distinct from the metadata used to resolve an indirect scalar. A malformed buffer can make those byte ranges overlap, so mutating the scalar can also mutate the offset used by later accesses. Rejecting this overlap during verification keeps verified indirect scalar references stable before callers use the public mutation APIs.

The bool mutation change preserves existing behavior while avoiding a wide copy from a 1-byte bool object when the parent storage width is larger.

Tests

  • env ASAN_OPTIONS=detect_leaks=0:abort_on_error=1 UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1 LD_LIBRARY_PATH=$PWD/toolchains/apt/usr/lib/x86_64-linux-gnu toolchains/apt/usr/bin/ctest --test-dir build/flatbuffers-patch-asan --output-on-failure
  • Local ASan repro: previously accepted overlapping indirect-int buffer now fails VerifyBuffer().
  • Local ASan repro: forced-width bool mutation succeeds without sanitizer findings.

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 12, 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 the c++ label May 12, 2026
@kmackinley kmackinley marked this pull request as ready for review May 12, 2026 16:46
@kmackinley kmackinley requested a review from dbaileychess as a code owner May 12, 2026 16:46
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