Set TextFormat default recursion limit to 100#26491
Open
gladiator9797 wants to merge 1 commit intoprotocolbuffers:mainfrom
Open
Set TextFormat default recursion limit to 100#26491gladiator9797 wants to merge 1 commit intoprotocolbuffers:mainfrom
gladiator9797 wants to merge 1 commit intoprotocolbuffers:mainfrom
Conversation
3 tasks
zhangskz
approved these changes
Mar 20, 2026
The TextFormat::Parser constructor initializes recursion_limit_ to
std::numeric_limits<int>::max() (2,147,483,647). This is inconsistent
with the binary format parser (default 100) and the JSON parser (default
64-100). A textproto with ~5,000-10,000 nested messages overflows the C
stack before the recursion check triggers, causing SIGSEGV.
Change the default to 100, matching CodedInputStream::default_recursion_limit_.
Users who need a different limit can still call SetRecursionLimit().
Reproducer:
Parse textproto with 10000 levels of nested_type { ... }
-> SIGSEGV (exit 139) due to stack overflow
9cd1ebe to
8991e76
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
TextFormat::Parserconstructor initializesrecursion_limit_tostd::numeric_limits<int>::max()(2,147,483,647) attext_format.cc:1803. This is inconsistent with:CodedInputStream::default_recursion_limit_)kUpb_WireFormat_DefaultDepthLimit)A textproto with ~5,000-10,000 nested messages overflows the C stack before the recursion check ever triggers, causing
SIGSEGV.Fix
Change the default from
std::numeric_limits<int>::max()to100, matchingCodedInputStream::default_recursion_limit_. Users who need a different limit can still callSetRecursionLimit().Reproducer
Test plan
SetRecursionLimit()API still works for custom limits