Skip to content

Commit a6d33d0

Browse files
committed
mdf create msg
1 parent cbb7d03 commit a6d33d0

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

‎src/main/java/org/tron/common/overlay/message/P2pMessageFactory.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@
2020

2121
import org.apache.commons.lang3.ArrayUtils;
2222
import org.tron.core.exception.P2pException;
23+
import org.tron.core.exception.P2pException.TypeEnum;
2324
import org.tron.core.net.message.MessageTypes;
2425

2526
public class P2pMessageFactory extends MessageFactory {
2627

2728
@Override
2829
public P2pMessage create(byte[] data) throws Exception{
30+
if (data.length <= 1){
31+
throw new P2pException(TypeEnum.MESSAGE_WITH_WRONG_LENGTH, "len=" + data.length);
32+
}
2933
try {
3034
byte type = data[0];
3135
byte[] rawData = ArrayUtils.subarray(data, 1, data.length);

‎src/main/java/org/tron/core/exception/P2pException.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public TypeEnum getType() {
1616
public enum TypeEnum {
1717
NO_SUCH_MESSAGE (1, "No such message"),
1818
PARSE_MESSAGE_FAILED (2, "Parse message failed"),
19+
MESSAGE_WITH_WRONG_LENGTH (3, "Message with wrong length"),
1920
DEFAULT (100, "default exception");
2021

2122
private Integer value;

‎src/main/java/org/tron/core/net/message/TronMessageFactory.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.apache.commons.lang3.ArrayUtils;
44
import org.tron.common.overlay.message.MessageFactory;
55
import org.tron.core.exception.P2pException;
6+
import org.tron.core.exception.P2pException.TypeEnum;
67

78
/**
89
* msg factory.
@@ -11,6 +12,9 @@ public class TronMessageFactory extends MessageFactory {
1112

1213
@Override
1314
public TronMessage create(byte[] data) throws Exception {
15+
if (data.length <= 1){
16+
throw new P2pException(TypeEnum.MESSAGE_WITH_WRONG_LENGTH, "len=" + data.length);
17+
}
1418
try {
1519
byte type = data[0];
1620
byte[] rawData = ArrayUtils.subarray(data, 1, data.length);

0 commit comments

Comments
 (0)