Skip to content

Commit 24abc3a

Browse files
bladehan1claude
andcommitted
fix(api): use httpMaxMessageSize in checkBodySize instead of gRPC limit
checkBodySize() was enforcing maxMessageSize (gRPC limit) instead of httpMaxMessageSize, causing the independent HTTP size setting to be ineffective at the servlet layer. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 674e547 commit 24abc3a

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

framework/src/main/java/org/tron/core/services/http/Util.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ public static Transaction packTransaction(String strTransaction, boolean selfTyp
330330
@Deprecated
331331
public static void checkBodySize(String body) throws Exception {
332332
CommonParameter parameter = Args.getInstance();
333-
if (body.getBytes().length > parameter.getMaxMessageSize()) {
334-
throw new Exception("body size is too big, the limit is " + parameter.getMaxMessageSize());
333+
if (body.getBytes().length > parameter.getHttpMaxMessageSize()) {
334+
throw new Exception("body size is too big, the limit is " + parameter.getHttpMaxMessageSize());
335335
}
336336
}
337337

framework/src/test/java/org/tron/core/services/http/UtilTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,32 @@ public void testPackTransactionWithInvalidType() {
129129
txSignWeight.getResult().getMessage());
130130
}
131131

132+
@Test
133+
public void testCheckBodySizeUsesHttpLimit() throws Exception {
134+
int originalHttpMax = Args.getInstance().getHttpMaxMessageSize();
135+
int originalRpcMax = Args.getInstance().getMaxMessageSize();
136+
try {
137+
// set httpMaxMessageSize larger than maxMessageSize
138+
Args.getInstance().setHttpMaxMessageSize(200);
139+
Args.getInstance().setMaxMessageSize(100);
140+
141+
String withinHttpLimit = new String(new char[150]).replace('\0', 'a');
142+
// should pass: 150 < httpMaxMessageSize(200), even though > maxMessageSize(100)
143+
Util.checkBodySize(withinHttpLimit);
144+
145+
String exceedsHttpLimit = new String(new char[201]).replace('\0', 'b');
146+
try {
147+
Util.checkBodySize(exceedsHttpLimit);
148+
Assert.fail("expected exception for body exceeding httpMaxMessageSize");
149+
} catch (Exception e) {
150+
Assert.assertTrue(e.getMessage().contains("200"));
151+
}
152+
} finally {
153+
Args.getInstance().setHttpMaxMessageSize(originalHttpMax);
154+
Args.getInstance().setMaxMessageSize(originalRpcMax);
155+
}
156+
}
157+
132158
@Test
133159
public void testPackTransaction() {
134160
String strTransaction = "{\n"

0 commit comments

Comments
 (0)