Skip to content

Commit a3d4983

Browse files
committed
restict size of address and topics
1 parent 1e8d839 commit a3d4983

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

framework/src/main/java/org/tron/core/services/jsonrpc/filters/LogFilter.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class LogFilter {
3535
@Setter
3636
private Bloom[][] filterBlooms;
3737

38+
private final int maxTopicDepth = 4;
39+
private final int maxSubWidth = 20;
3840

3941
public LogFilter() {
4042
}
@@ -58,6 +60,9 @@ public LogFilter(FilterRequest fr) throws JsonRpcInvalidParamsException {
5860
String.format("invalid address at index %d: %s", i, s));
5961
}
6062
}
63+
if (addr.size() > maxSubWidth) {
64+
throw new JsonRpcInvalidParamsException("address size should be <= " + maxSubWidth);
65+
}
6166
withContractAddress(addr.toArray(new byte[addr.size()][]));
6267

6368
} else if (fr.getAddress() != null) {
@@ -66,8 +71,8 @@ public LogFilter(FilterRequest fr) throws JsonRpcInvalidParamsException {
6671

6772
if (fr.getTopics() != null) {
6873
//restrict depth of topics, because event has a signature and most 3 indexed parameters
69-
if (fr.getTopics().length > 4) {
70-
throw new JsonRpcInvalidParamsException("topics size should be <= 4");
74+
if (fr.getTopics().length > maxTopicDepth) {
75+
throw new JsonRpcInvalidParamsException("topics size should be <= " + maxTopicDepth);
7176
}
7277
for (Object topic : fr.getTopics()) {
7378
if (topic == null) {
@@ -88,6 +93,9 @@ public LogFilter(FilterRequest fr) throws JsonRpcInvalidParamsException {
8893
throw new JsonRpcInvalidParamsException("invalid topic(s): " + s);
8994
}
9095
}
96+
if (t.size() > maxSubWidth) {
97+
throw new JsonRpcInvalidParamsException("topics' width should be <= " + maxSubWidth);
98+
}
9199
withTopic(t.toArray(new byte[t.size()][]));
92100
} else {
93101
throw new JsonRpcInvalidParamsException("invalid topic(s)");

framework/src/test/java/org/tron/core/jsonrpc/JsonRpcTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,21 @@ public void testLogFilter() {
240240
} catch (JsonRpcInvalidParamsException e) {
241241
Assert.assertTrue(e.getMessage().contains("invalid address"));
242242
}
243+
244+
//address width should be <= 20
245+
246+
//topic's width should be <= 20
247+
List<String> subTopics = new ArrayList<>();
248+
for (int i = 0; i < 100; i++) {
249+
subTopics.add("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef");
250+
}
251+
Object[] topics = new Object[1];
252+
topics[0] = subTopics;
253+
try {
254+
new LogFilter(new FilterRequest(null, null, null, topics, null));
255+
} catch (JsonRpcInvalidParamsException e) {
256+
Assert.assertEquals("topics' width should be <= 20", e.getMessage());
257+
}
243258
}
244259

245260
private int[] getBloomIndex(String s) {

0 commit comments

Comments
 (0)