From 43e1657cdff986eda44bf2ea437fa75c2d2a22b0 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Mon, 31 Jul 2023 13:14:25 -0700 Subject: [PATCH] Lower default Java text format recursion limit down to 100 This makes the limit consistent with how we handle this in binary format and in other languages. PiperOrigin-RevId: 552572322 --- .../src/main/java/com/google/protobuf/TextFormat.java | 2 +- .../src/test/java/com/google/protobuf/TextFormatTest.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/TextFormat.java b/java/core/src/main/java/com/google/protobuf/TextFormat.java index 6c407cac5137..53b93b6e1fb8 100644 --- a/java/core/src/main/java/com/google/protobuf/TextFormat.java +++ b/java/core/src/main/java/com/google/protobuf/TextFormat.java @@ -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 diff --git a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java index ec5f97428424..11c1c07ea05a 100644 --- a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java +++ b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java @@ -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");