Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the recursion limit to match grpc's default #3091

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ open class ProtoReader(private val source: BufferedSource) {

companion object {
/** The standard number of levels of message nesting to allow. */
internal const val RECURSION_LIMIT = 65
internal const val RECURSION_LIMIT = 100

internal const val FIELD_ENCODING_MASK = 0x7
internal const val TAG_FIELD_ENCODING_BITS = 3
Expand Down
24 changes: 14 additions & 10 deletions wire-tests/src/commonTest/kotlin/com/squareup/wire/ParseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,31 @@ class ParseTest {

@Test
fun upToRecursionLimit() {
// tag 2: nested message (64 times)
// tag 2: nested message (99 times)
// tag 1: signed varint32 456
val data = (
"127e127c127a12781276127412721270126e126c126a12681266126" +
"412621260125e125c125a12581256125412521250124e124c124a12481246124412421240123e123c123a123" +
"81236123412321230122e122c122a12281226122412221220121e121c121a12181216121412121210120e120" +
"c120a1208120612041202120008c803"
"12e60112e30112e00112dd0112da0112d70112d40112d10112ce0112cb0112c80112c50112c20112bf0112bc" +
"0112b90112b60112b30112b00112ad0112aa0112a70112a40112a101129e01129b01129801129501129201" +
"128f01128c01128901128601128301128001127e127c127a12781276127412721270126e126c126a126812" +
"66126412621260125e125c125a12581256125412521250124e124c124a12481246124412421240123e123c" +
"123a12381236123412321230122e122c122a12281226122412221220121e121c121a121812161214121212" +
"10120e120c120a1208120612041202120008c803"
).decodeHex()
val recursive = Recursive.ADAPTER.decode(data.toByteArray())
assertEquals(456, recursive.value_!!.toInt())
}

@Test
fun overRecursionLimitThrowsIOException() {
// tag 2: nested message (65 times)
// tag 2: nested message (100 times)
// tag 1: signed varint32 456
val data = (
"128001127e127c127a12781276127412721270126e126c126a12681" +
"266126412621260125e125c125a12581256125412521250124e124c124a12481246124412421240123e123c1" +
"23a12381236123412321230122e122c122a12281226122412221220121e121c121a121812161214121212101" +
"20e120c120a1208120612041202120008c803"
"12e90112e60112e30112e00112dd0112da0112d70112d40112d10112ce0112cb0112c80112c50112c20112bf" +
"0112bc0112b90112b60112b30112b00112ad0112aa0112a70112a40112a101129e01129b01129801129501" +
"129201128f01128c01128901128601128301128001127e127c127a12781276127412721270126e126c126a" +
"12681266126412621260125e125c125a12581256125412521250124e124c124a1248124612441242124012" +
"3e123c123a12381236123412321230122e122c122a12281226122412221220121e121c121a121812161214" +
"12121210120e120c120a1208120612041202120008c803"
).decodeHex()
try {
Recursive.ADAPTER.decode(data.toByteArray())
Expand Down
24 changes: 14 additions & 10 deletions wire-tests/src/jvmJavaTest/java/com/squareup/wire/ParseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,32 @@ public void lastValueWinsForRepeatedValueOfNonrepeatedField() throws Exception {

@Test
public void upToRecursionLimit() throws Exception {
// tag 2: nested message (64 times)
// tag 2: nested message (99 times)
// tag 1: signed varint32 456
ByteString data =
ByteString.decodeHex(
"127e127c127a12781276127412721270126e126c126a12681266126"
+ "412621260125e125c125a12581256125412521250124e124c124a12481246124412421240123e123c123a123"
+ "81236123412321230122e122c122a12281226122412221220121e121c121a12181216121412121210120e120"
+ "c120a1208120612041202120008c803");
"12e60112e30112e00112dd0112da0112d70112d40112d10112ce0112cb0112c80112c50112c20112bf0112bc"
+ "0112b90112b60112b30112b00112ad0112aa0112a70112a40112a101129e01129b01129801129501129201"
+ "128f01128c01128901128601128301128001127e127c127a12781276127412721270126e126c126a126812"
+ "66126412621260125e125c125a12581256125412521250124e124c124a12481246124412421240123e123c"
+ "123a12381236123412321230122e122c122a12281226122412221220121e121c121a121812161214121212"
+ "10120e120c120a1208120612041202120008c803");
Recursive recursive = Recursive.ADAPTER.decode(data.toByteArray());
assertThat(recursive.value.intValue()).isEqualTo(456);
}

@Test
public void overRecursionLimitThrowsIOException() throws Exception {
// tag 2: nested message (65 times)
// tag 2: nested message (100 times)
// tag 1: signed varint32 456
ByteString data =
ByteString.decodeHex(
"128001127e127c127a12781276127412721270126e126c126a12681"
+ "266126412621260125e125c125a12581256125412521250124e124c124a12481246124412421240123e123c1"
+ "23a12381236123412321230122e122c122a12281226122412221220121e121c121a121812161214121212101"
+ "20e120c120a1208120612041202120008c803");
"12e90112e60112e30112e00112dd0112da0112d70112d40112d10112ce0112cb0112c80112c50112c20112bf"
+ "0112bc0112b90112b60112b30112b00112ad0112aa0112a70112a40112a101129e01129b01129801129501"
+ "129201128f01128c01128901128601128301128001127e127c127a12781276127412721270126e126c126a"
+ "12681266126412621260125e125c125a12581256125412521250124e124c124a1248124612441242124012"
+ "3e123c123a12381236123412321230122e122c122a12281226122412221220121e121c121a121812161214"
+ "12121210120e120c120a1208120612041202120008c803");
try {
Recursive.ADAPTER.decode(data.toByteArray());
fail();
Expand Down