Skip to content

Commit

Permalink
Lower default Java text format recursion limit down to 100
Browse files Browse the repository at this point in the history
This makes the limit consistent with how we handle this in binary format and in
other languages.

PiperOrigin-RevId: 552572322
  • Loading branch information
acozzette authored and copybara-github committed Jul 31, 2023
1 parent bca3bed commit 43e1657
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ public static class Builder {
SingularOverwritePolicy.ALLOW_SINGULAR_OVERWRITES;
private TextFormatParseInfoTree.Builder parseInfoTreeBuilder = null;
private TypeRegistry typeRegistry = TypeRegistry.getEmptyTypeRegistry();
private int recursionLimit = 150;
private int recursionLimit = 100;

/**
* Sets the TypeRegistry for resolving Any. If this is not set, TextFormat will not be able to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1854,11 +1854,11 @@ private TestRecursiveMessage makeRecursiveMessage(int depth) {

@Test
public void testDefaultRecursionLimit() throws Exception {
String depth150 = TextFormat.printer().printToString(makeRecursiveMessage(150));
String depth151 = TextFormat.printer().printToString(makeRecursiveMessage(151));
TextFormat.parse(depth150, TestRecursiveMessage.class);
String depth100 = TextFormat.printer().printToString(makeRecursiveMessage(100));
String depth101 = TextFormat.printer().printToString(makeRecursiveMessage(101));
TextFormat.parse(depth100, TestRecursiveMessage.class);
try {
TextFormat.parse(depth151, TestRecursiveMessage.class);
TextFormat.parse(depth101, TestRecursiveMessage.class);
assertWithMessage("Parsing deep message should have failed").fail();
} catch (TextFormat.ParseException e) {
assertThat(e).hasMessageThat().contains("too deep");
Expand Down

0 comments on commit 43e1657

Please sign in to comment.