Skip to content

Commit 0f9fc76

Browse files
committed
fix(vm): reject header-only calldata in canonical ABI check
1 parent a5f1718 commit 0f9fc76

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

actuator/src/main/java/org/tron/core/vm/PrecompiledContracts.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import static java.util.Arrays.copyOfRange;
44
import static org.tron.common.math.Maths.max;
55
import 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;
68
import static org.tron.common.runtime.vm.DataWord.WORD_SIZE;
79
import static org.tron.common.utils.BIUtil.addSafely;
810
import static org.tron.common.utils.BIUtil.isLessThan;
@@ -418,8 +420,8 @@ private static boolean isValidAbiEncoding(byte[] data, int headerWords, int item
418420
if (data == null || data.length % WORD_SIZE != 0) {
419421
return false;
420422
}
421-
int tail = data.length - headerWords * WORD_SIZE;
422-
return tail >= 0 && tail % (itemWords * WORD_SIZE) == 0;
423+
long tail = subtractExact(data.length, multiplyExact(headerWords, WORD_SIZE));
424+
return tail > 0 && tail % multiplyExact(itemWords, WORD_SIZE) == 0;
423425
}
424426

425427
public abstract static class PrecompiledContract {

0 commit comments

Comments
 (0)