Skip to content

Commit d719bd9

Browse files
Add comment closer to the TextFormat default recursion limit stressing that it is working as intended and will not be changed in the near term.
PiperOrigin-RevId: 908365390
1 parent 1a92d8c commit d719bd9

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/google/protobuf/text_format.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,20 @@ MessageFactory* TextFormat::Finder::FindExtensionFactory(
19261926

19271927
// ===========================================================================
19281928

1929+
// Note: this value is intentionally unbounded by default. This is due to the
1930+
// use-cases of TextProto primarily being to parse trusted inputs, alongside a
1931+
// strong need to avoid breaking long-standing and working as intended usages
1932+
// parsing messages which exceed depth 100. Use-cases which need to limit this
1933+
// (e.g. anything parsing of untrusted TextProto inputs) must explicitly opt
1934+
// into a limit.
1935+
//
1936+
// At a future date we may consider reducing this default, but we have
1937+
// no concrete plans to do so. PRs proposing to reduce this value to 100
1938+
// unfortunately will not be accepted at this time.
1939+
//
1940+
// See comment on TextFormat class in text_format.h for more info.
1941+
static constexpr int kDefaultRecursionLimit = std::numeric_limits<int>::max();
1942+
19291943
TextFormat::Parser::Parser()
19301944
: error_collector_(nullptr),
19311945
finder_(nullptr),
@@ -1938,7 +1952,7 @@ TextFormat::Parser::Parser()
19381952
allow_field_number_(false),
19391953
allow_relaxed_whitespace_(false),
19401954
allow_singular_overwrites_(false),
1941-
recursion_limit_(std::numeric_limits<int>::max()) {}
1955+
recursion_limit_(kDefaultRecursionLimit) {}
19421956

19431957
namespace {
19441958

0 commit comments

Comments
 (0)