Skip to content

Commit bb14edd

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 f360750 commit bb14edd

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
@@ -536,15 +536,19 @@ public static void applyConfigParams(
536536
PARAMETER.httpMaxMessageSize = config.hasPath(ConfigKey.NODE_HTTP_MAX_MESSAGE_SIZE)
537537
? config.getMemorySize(ConfigKey.NODE_HTTP_MAX_MESSAGE_SIZE).toBytes()
538538
: defaultMaxMessageSize;
539-
if (PARAMETER.httpMaxMessageSize < 0) {
540-
throw new TronError("node.http.maxMessageSize must be non-negative, got: "
539+
if (PARAMETER.httpMaxMessageSize < 0
540+
|| PARAMETER.httpMaxMessageSize > Integer.MAX_VALUE) {
541+
throw new TronError("node.http.maxMessageSize must be non-negative and <= "
542+
+ Integer.MAX_VALUE + ", got: "
541543
+ PARAMETER.httpMaxMessageSize, PARAMETER_INIT);
542544
}
543545
PARAMETER.jsonRpcMaxMessageSize = config.hasPath(ConfigKey.NODE_JSONRPC_MAX_MESSAGE_SIZE)
544546
? config.getMemorySize(ConfigKey.NODE_JSONRPC_MAX_MESSAGE_SIZE).toBytes()
545547
: defaultMaxMessageSize;
546-
if (PARAMETER.jsonRpcMaxMessageSize < 0) {
547-
throw new TronError("node.jsonrpc.maxMessageSize must be non-negative, got: "
548+
if (PARAMETER.jsonRpcMaxMessageSize < 0
549+
|| PARAMETER.jsonRpcMaxMessageSize > Integer.MAX_VALUE) {
550+
throw new TronError("node.jsonrpc.maxMessageSize must be non-negative and <= "
551+
+ Integer.MAX_VALUE + ", got: "
548552
+ PARAMETER.jsonRpcMaxMessageSize, PARAMETER_INIT);
549553
}
550554

‎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
@@ -417,7 +417,7 @@ public void testMaxMessageSizeHumanReadable() {
417417
Args.clearParam();
418418

419419
// --- GB tier: binary (g/G/Gi/GiB) vs SI (GB) ---
420-
// rpc is int-bounded, only test http/jsonrpc for GB values
420+
// All three paths are int-bounded; values up to Integer.MAX_VALUE are accepted.
421421
configMap.put("node.rpc.maxMessageSize", "4m");
422422
configMap.put("node.http.maxMessageSize", "1g");
423423
configMap.put("node.jsonrpc.maxMessageSize", "1GB");
@@ -429,17 +429,6 @@ public void testMaxMessageSizeHumanReadable() {
429429
Assert.assertEquals(1000L * 1000 * 1000, Args.getInstance().getJsonRpcMaxMessageSize());
430430
Args.clearParam();
431431

432-
configMap.put("node.rpc.maxMessageSize", "4m");
433-
configMap.put("node.http.maxMessageSize", "2Gi");
434-
configMap.put("node.jsonrpc.maxMessageSize", "2GiB");
435-
config = ConfigFactory.defaultOverrides()
436-
.withFallback(ConfigFactory.parseMap(configMap));
437-
Args.applyConfigParams(config);
438-
Assert.assertEquals(4 * 1024 * 1024, Args.getInstance().getMaxMessageSize());
439-
Assert.assertEquals(2L * 1024 * 1024 * 1024, Args.getInstance().getHttpMaxMessageSize());
440-
Assert.assertEquals(2L * 1024 * 1024 * 1024, Args.getInstance().getJsonRpcMaxMessageSize());
441-
Args.clearParam();
442-
443432
// --- raw integer (backward compatible): treated as bytes ---
444433
configMap.put("node.rpc.maxMessageSize", "4194304");
445434
configMap.put("node.http.maxMessageSize", "4194304");
@@ -477,6 +466,31 @@ public void testRpcMaxMessageSizeExceedsIntMax() {
477466
Assert.assertTrue(e.getMessage().contains("node.rpc.maxMessageSize must be non-negative"));
478467
}
479468

469+
@Test
470+
public void testHttpMaxMessageSizeExceedsIntMax() {
471+
Map<String, String> configMap = new HashMap<>();
472+
configMap.put("storage.db.directory", "database");
473+
configMap.put("node.http.maxMessageSize", "2Gi");
474+
Config config = ConfigFactory.defaultOverrides()
475+
.withFallback(ConfigFactory.parseMap(configMap));
476+
TronError e = Assert.assertThrows(TronError.class,
477+
() -> Args.applyConfigParams(config));
478+
Assert.assertTrue(e.getMessage().contains("node.http.maxMessageSize must be non-negative"));
479+
}
480+
481+
@Test
482+
public void testJsonRpcMaxMessageSizeExceedsIntMax() {
483+
Map<String, String> configMap = new HashMap<>();
484+
configMap.put("storage.db.directory", "database");
485+
configMap.put("node.jsonrpc.maxMessageSize", "2Gi");
486+
Config config = ConfigFactory.defaultOverrides()
487+
.withFallback(ConfigFactory.parseMap(configMap));
488+
TronError e = Assert.assertThrows(TronError.class,
489+
() -> Args.applyConfigParams(config));
490+
Assert.assertTrue(
491+
e.getMessage().contains("node.jsonrpc.maxMessageSize must be non-negative"));
492+
}
493+
480494
@Test
481495
public void testMaxMessageSizeNegativeValue() {
482496
Map<String, String> configMap = new HashMap<>();

0 commit comments

Comments
 (0)