Skip to content

Commit 64ca1bd

Browse files
committed
fix(config): cap http/jsonrpc maxMessageSize at Integer.MAX_VALUE
Align node.http.maxMessageSize and node.jsonrpc.maxMessageSize with the existing node.rpc.maxMessageSize rule: reject values > Integer.MAX_VALUE at startup with TronError. Downstream body materialization is int-bounded (String/byte[]/StringBuilder all cap at Integer.MAX_VALUE), so config values beyond that produced an ambiguous silent mismatch; fail-fast is safer than a runtime NegativeArraySizeException or truncation surprise. Update config.conf docblocks (http/rpc/jsonrpc) to state the full constraint. Replace the obsolete 2Gi success assertion in testMaxMessageSizeHumanReadable, add testHttpMaxMessageSizeExceedsIntMax and testJsonRpcMaxMessageSizeExceedsIntMax mirroring the existing rpc case.
1 parent 81dd2e2 commit 64ca1bd

3 files changed

Lines changed: 40 additions & 19 deletions

File tree

framework/src/main/java/org/tron/core/config/args/Args.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,19 @@ public static void applyConfigParams(
484484
PARAMETER.httpMaxMessageSize = config.hasPath(ConfigKey.NODE_HTTP_MAX_MESSAGE_SIZE)
485485
? config.getMemorySize(ConfigKey.NODE_HTTP_MAX_MESSAGE_SIZE).toBytes()
486486
: defaultMaxMessageSize;
487-
if (PARAMETER.httpMaxMessageSize < 0) {
488-
throw new TronError("node.http.maxMessageSize must be non-negative, got: "
487+
if (PARAMETER.httpMaxMessageSize < 0
488+
|| PARAMETER.httpMaxMessageSize > Integer.MAX_VALUE) {
489+
throw new TronError("node.http.maxMessageSize must be non-negative and <= "
490+
+ Integer.MAX_VALUE + ", got: "
489491
+ PARAMETER.httpMaxMessageSize, PARAMETER_INIT);
490492
}
491493
PARAMETER.jsonRpcMaxMessageSize = config.hasPath(ConfigKey.NODE_JSONRPC_MAX_MESSAGE_SIZE)
492494
? config.getMemorySize(ConfigKey.NODE_JSONRPC_MAX_MESSAGE_SIZE).toBytes()
493495
: defaultMaxMessageSize;
494-
if (PARAMETER.jsonRpcMaxMessageSize < 0) {
495-
throw new TronError("node.jsonrpc.maxMessageSize must be non-negative, got: "
496+
if (PARAMETER.jsonRpcMaxMessageSize < 0
497+
|| PARAMETER.jsonRpcMaxMessageSize > Integer.MAX_VALUE) {
498+
throw new TronError("node.jsonrpc.maxMessageSize must be non-negative and <= "
499+
+ Integer.MAX_VALUE + ", got: "
496500
+ PARAMETER.jsonRpcMaxMessageSize, PARAMETER_INIT);
497501
}
498502

framework/src/main/resources/config.conf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ node {
225225
PBFTPort = 8092
226226

227227
# The maximum request body size for HTTP API, default 4M (4194304 bytes).
228-
# Supports human-readable sizes: 4m, 4MB, 4194304. Must be non-negative.
228+
# Supports human-readable sizes: 4m, 4MB, 4194304.
229+
# Must be non-negative and <= 2147483647 (Integer.MAX_VALUE, ~2 GiB).
229230
# Setting to 0 rejects all non-empty request bodies (not "unlimited").
230231
# maxMessageSize = 4m
231232
}
@@ -254,7 +255,8 @@ node {
254255
# maxConnectionAgeInMillis =
255256

256257
# The maximum message size allowed to be received on the server, default 4M (4194304 bytes).
257-
# Supports human-readable sizes: 4m, 4MB, 4194304. Must be non-negative.
258+
# Supports human-readable sizes: 4m, 4MB, 4194304.
259+
# Must be non-negative and <= 2147483647 (Integer.MAX_VALUE, ~2 GiB).
258260
# Setting to 0 rejects all non-empty request bodies (not "unlimited").
259261
# maxMessageSize = 4m
260262

@@ -365,7 +367,8 @@ node {
365367

366368
jsonrpc {
367369
# The maximum request body size for JSON-RPC API, default 4M (4194304 bytes).
368-
# Supports human-readable sizes: 4m, 4MB, 4194304. Must be non-negative.
370+
# Supports human-readable sizes: 4m, 4MB, 4194304.
371+
# Must be non-negative and <= 2147483647 (Integer.MAX_VALUE, ~2 GiB).
369372
# Setting to 0 rejects all non-empty request bodies (not "unlimited").
370373
# maxMessageSize = 4m
371374

framework/src/test/java/org/tron/core/config/args/ArgsTest.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ public void testMaxMessageSizeHumanReadable() {
398398
Args.clearParam();
399399

400400
// --- GB tier: binary (g/G/Gi/GiB) vs SI (GB) ---
401-
// rpc is int-bounded, only test http/jsonrpc for GB values
401+
// All three paths are int-bounded; values up to Integer.MAX_VALUE are accepted.
402402
configMap.put("node.rpc.maxMessageSize", "4m");
403403
configMap.put("node.http.maxMessageSize", "1g");
404404
configMap.put("node.jsonrpc.maxMessageSize", "1GB");
@@ -410,17 +410,6 @@ public void testMaxMessageSizeHumanReadable() {
410410
Assert.assertEquals(1000L * 1000 * 1000, Args.getInstance().getJsonRpcMaxMessageSize());
411411
Args.clearParam();
412412

413-
configMap.put("node.rpc.maxMessageSize", "4m");
414-
configMap.put("node.http.maxMessageSize", "2Gi");
415-
configMap.put("node.jsonrpc.maxMessageSize", "2GiB");
416-
config = ConfigFactory.defaultOverrides()
417-
.withFallback(ConfigFactory.parseMap(configMap));
418-
Args.applyConfigParams(config);
419-
Assert.assertEquals(4 * 1024 * 1024, Args.getInstance().getMaxMessageSize());
420-
Assert.assertEquals(2L * 1024 * 1024 * 1024, Args.getInstance().getHttpMaxMessageSize());
421-
Assert.assertEquals(2L * 1024 * 1024 * 1024, Args.getInstance().getJsonRpcMaxMessageSize());
422-
Args.clearParam();
423-
424413
// --- raw integer (backward compatible): treated as bytes ---
425414
configMap.put("node.rpc.maxMessageSize", "4194304");
426415
configMap.put("node.http.maxMessageSize", "4194304");
@@ -458,6 +447,31 @@ public void testRpcMaxMessageSizeExceedsIntMax() {
458447
Assert.assertTrue(e.getMessage().contains("node.rpc.maxMessageSize must be non-negative"));
459448
}
460449

450+
@Test
451+
public void testHttpMaxMessageSizeExceedsIntMax() {
452+
Map<String, String> configMap = new HashMap<>();
453+
configMap.put("storage.db.directory", "database");
454+
configMap.put("node.http.maxMessageSize", "2Gi");
455+
Config config = ConfigFactory.defaultOverrides()
456+
.withFallback(ConfigFactory.parseMap(configMap));
457+
TronError e = Assert.assertThrows(TronError.class,
458+
() -> Args.applyConfigParams(config));
459+
Assert.assertTrue(e.getMessage().contains("node.http.maxMessageSize must be non-negative"));
460+
}
461+
462+
@Test
463+
public void testJsonRpcMaxMessageSizeExceedsIntMax() {
464+
Map<String, String> configMap = new HashMap<>();
465+
configMap.put("storage.db.directory", "database");
466+
configMap.put("node.jsonrpc.maxMessageSize", "2Gi");
467+
Config config = ConfigFactory.defaultOverrides()
468+
.withFallback(ConfigFactory.parseMap(configMap));
469+
TronError e = Assert.assertThrows(TronError.class,
470+
() -> Args.applyConfigParams(config));
471+
Assert.assertTrue(
472+
e.getMessage().contains("node.jsonrpc.maxMessageSize must be non-negative"));
473+
}
474+
461475
@Test
462476
public void testMaxMessageSizeNegativeValue() {
463477
Map<String, String> configMap = new HashMap<>();

0 commit comments

Comments
 (0)