Skip to content

Commit 7060326

Browse files
fix: DEFAULT_MAX_DEPTH = 512 (#690)
Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
1 parent f5bb21d commit 7060326

File tree

1 file changed

+12
-2
lines changed
  • pbj-core/pbj-runtime/src/main/java/com/hedera/pbj/runtime

1 file changed

+12
-2
lines changed

pbj-core/pbj-runtime/src/main/java/com/hedera/pbj/runtime/Codec.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ public interface Codec<T> {
2525
*/
2626
int DEFAULT_MAX_SIZE = 2 * 1024 * 1024;
2727

28+
/**
29+
* The default maximum depth of nested messages before the `parse()` method would error out.
30+
* The current default value may be slightly high, and it would be ideal to lower it in the future.
31+
* However, it's known that serialized data exists that may require a somewhat high value for maxDepth.
32+
* Also, the current value is much safer than the previously used Integer.MAX_VALUE.
33+
* Applications can always override the maxDepth by supplying an argument to the main `Codec.parse()` method.
34+
* The default depth should not be increased beyond the current limit because of the safety concerns.
35+
*/
36+
int DEFAULT_MAX_DEPTH = 512;
37+
2838
/**
2939
* Parses an object from the {@link ReadableSequentialData} and returns it.
3040
* <p>
@@ -147,7 +157,7 @@ default T parse(@NonNull Bytes bytes, final boolean strictMode, final int maxDep
147157
*/
148158
@NonNull
149159
default T parse(@NonNull ReadableSequentialData input) throws ParseException {
150-
return parse(input, false, Integer.MAX_VALUE);
160+
return parse(input, false, DEFAULT_MAX_DEPTH);
151161
}
152162

153163
/**
@@ -175,7 +185,7 @@ default T parse(@NonNull Bytes bytes) throws ParseException {
175185
*/
176186
@NonNull
177187
default T parseStrict(@NonNull ReadableSequentialData input) throws ParseException {
178-
return parse(input, true, Integer.MAX_VALUE);
188+
return parse(input, true, DEFAULT_MAX_DEPTH);
179189
}
180190

181191
/**

0 commit comments

Comments
 (0)