33import static java .util .Arrays .copyOfRange ;
44import static org .tron .common .math .Maths .max ;
55import static org .tron .common .math .Maths .min ;
6+ import static org .tron .common .math .StrictMathWrapper .multiplyExact ;
7+ import static org .tron .common .math .StrictMathWrapper .subtractExact ;
68import static org .tron .common .runtime .vm .DataWord .WORD_SIZE ;
79import static org .tron .common .utils .BIUtil .addSafely ;
810import static org .tron .common .utils .BIUtil .isLessThan ;
@@ -427,6 +429,14 @@ private static byte[] extractBytes(byte[] data, int offset, int len) {
427429 return Arrays .copyOfRange (data , offset , offset + len );
428430 }
429431
432+ private static boolean isValidAbiEncoding (byte [] data , int headerWords , int itemWords ) {
433+ if (data == null || data .length % WORD_SIZE != 0 ) {
434+ return false ;
435+ }
436+ long tail = subtractExact (data .length , multiplyExact (headerWords , WORD_SIZE ));
437+ return tail > 0 && tail % multiplyExact (itemWords , WORD_SIZE ) == 0 ;
438+ }
439+
430440 public abstract static class PrecompiledContract {
431441
432442 protected static final byte [] DATA_FALSE = new byte [WORD_SIZE ];
@@ -1020,6 +1030,8 @@ public static class ValidateMultiSign extends PrecompiledContract {
10201030
10211031 private static final int ENGERYPERSIGN = 1500 ;
10221032 private static final int MAX_SIZE = 5 ;
1033+ private static final int ABI_HEADER_WORDS = 5 ;
1034+ private static final int ABI_ITEM_WORDS = 5 ;
10231035
10241036
10251037 @ Override
@@ -1031,6 +1043,10 @@ public long getEnergyForData(byte[] data) {
10311043
10321044 @ Override
10331045 public Pair <Boolean , byte []> execute (byte [] rawData ) {
1046+ if (VMConfig .allowTvmOsaka ()
1047+ && !isValidAbiEncoding (rawData , ABI_HEADER_WORDS , ABI_ITEM_WORDS )) {
1048+ return Pair .of (false , EMPTY_BYTE_ARRAY );
1049+ }
10341050 DataWord [] words = DataWord .parseArray (rawData );
10351051 byte [] address = words [0 ].toTronAddress ();
10361052 int permissionId = words [1 ].intValueSafe ();
@@ -1103,6 +1119,8 @@ public static class BatchValidateSign extends PrecompiledContract {
11031119 private static final String workersName = "validate-sign-contract" ;
11041120 private static final int ENGERYPERSIGN = 1500 ;
11051121 private static final int MAX_SIZE = 16 ;
1122+ private static final int ABI_HEADER_WORDS = 5 ;
1123+ private static final int ABI_ITEM_WORDS = 6 ;
11061124
11071125 static {
11081126 workers = ExecutorServiceManager .newFixedThreadPool (workersName ,
@@ -1130,6 +1148,10 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
11301148
11311149 private Pair <Boolean , byte []> doExecute (byte [] data )
11321150 throws InterruptedException , ExecutionException {
1151+ if (VMConfig .allowTvmOsaka ()
1152+ && !isValidAbiEncoding (data , ABI_HEADER_WORDS , ABI_ITEM_WORDS )) {
1153+ return Pair .of (false , EMPTY_BYTE_ARRAY );
1154+ }
11331155 DataWord [] words = DataWord .parseArray (data );
11341156 byte [] hash = words [0 ].getData ();
11351157
0 commit comments