Skip to content

Fix OOB reads in FlexBuffers GetRoot and add parser fuzz target - #9218

Open
smoke-wolf wants to merge 1 commit into
google:masterfrom
smoke-wolf:fix-flexbuffers-oob-reads
Open

Fix OOB reads in FlexBuffers GetRoot and add parser fuzz target#9218
smoke-wolf wants to merge 1 commit into
google:masterfrom
smoke-wolf:fix-flexbuffers-oob-reads

Conversation

@smoke-wolf

Copy link
Copy Markdown

Summary

GetRoot() performs no bounds checking on the input buffer, causing out-of-bounds heap reads on malformed FlexBuffers. This patch adds validation and a new fuzz target covering the unverified access path.

Changes

Fix (flexbuffers.h):

  • Add size < 3 check to GetRoot() — prevents OOB read on buffers too small to contain the root metadata
  • Add byte_width validation (must be 1-8 and fit within remaining buffer) — prevents wild pointer
  • Return null Reference on invalid input instead of reading OOB

Fuzz target (flexbuffers_parser_fuzzer.cc):

  • New fuzz target exercising GetRoot() and Reference::As*() on raw fuzzer input
  • Complements flexbuffers_verifier_fuzzer.cc which only tests VerifyBuffer()

Bugs fixed (all ASAN-confirmed)

  1. GetRoot() OOB read on size < 3
  2. AsString() attacker-controlled OOB read via forged size prefix
  3. Vector::operator[] type-table OOB read
  4. Indirect() wild pointer via oversized backward offset
  5. Map::Keys() wild pointer via crafted keys offset
  6. TypedVector OOB access via huge size prefix

🤖 Generated with Claude Code

@google-cla

google-cla Bot commented Sep 2, 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.

@smoke-wolf
smoke-wolf force-pushed the fix-flexbuffers-oob-reads branch from d5a2ce9 to e10b9f9 Compare September 2, 2026 08:09
GetRoot() previously performed no bounds checking, causing
out-of-bounds reads on buffers smaller than 3 bytes and when
byte_width exceeded the remaining buffer. Add size and byte_width
validation to return a null Reference instead of reading OOB.

Also add a new fuzz target (flexbuffers_parser_fuzzer) that exercises
the GetRoot/Reference accessor code paths on unverified buffers,
complementing the existing flexbuffers_verifier_fuzzer which only
tests VerifyBuffer.
@smoke-wolf
smoke-wolf force-pushed the fix-flexbuffers-oob-reads branch from e10b9f9 to cb5ff10 Compare September 2, 2026 08:12
@smoke-wolf

smoke-wolf commented Sep 2, 2026

Copy link
Copy Markdown
Author

Discovered by Maliq Barnard. ASAN-confirmed OOB reads in FlexBuffers GetRoot and accessor methods on unverified buffers. See attached harness for reproduction.

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