Skip to content

Fix Stack Overflow DoS via Unbounded Recursion in idl_gen_text.cpp#9037

Open
YLChen-007 wants to merge 1 commit intogoogle:masterfrom
YLChen-007:fix-idl-gen-text-dos
Open

Fix Stack Overflow DoS via Unbounded Recursion in idl_gen_text.cpp#9037
YLChen-007 wants to merge 1 commit intogoogle:masterfrom
YLChen-007:fix-idl-gen-text-dos

Conversation

@YLChen-007
Copy link
Copy Markdown

Fix Stack Overflow DoS via Unbounded Recursion in idl_gen_text.cpp

Description

A Denial of Service (DoS) vulnerability exists in the flatc compiler when converting binary FlatBuffers to text/JSON format. A missing recursion depth guard in idl_gen_text.cpp allows a maliciously crafted, deeply nested binary FlatBuffer (e.g., via a self-referencing table) to cause unbounded recursion between the GenStruct and PrintOffset functions. Processing such a file exhausts the process stack, resulting in an immediate segmentation fault (SIGSEGV).

This PR adds a depth_limit check to JsonPrinter (matching FLATBUFFERS_MAX_PARSING_DEPTH), guarded via a DepthGuard scope manager, to safely catch arbitrarily nested inputs and return a text generation error instead of exhausting the C++ call stack.

Testing

Compiled flatc and successfully tested against an evil.bin (depth > 20,000) generated targeting an explicitly recursive schema (table Node { child: Node; }).

Without the patch:
./flatc --raw-binary -t nest.fbs -- evil.bin -> Segmentation fault

With the patch:
./flatc --raw-binary -t nest.fbs -- evil.bin -> error: Unable to generate text for evil (error: text generation depth limit exceeded)

@github-actions github-actions bot added c++ codegen Involving generating code from schema labels Apr 10, 2026
@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 10, 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.

@YLChen-007 YLChen-007 force-pushed the fix-idl-gen-text-dos branch from 08f1cf3 to 3a8d697 Compare April 12, 2026 02:55
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant