Skip to content

Commit 0266e25

Browse files
authored
Merge pull request tronprotocol#2494 from tronprotocol/feature/v3.6.5_addvalimutisign
Make precompiledContracts extractBytesArray method safe
2 parents 7d5f6e7 + 38bcebc commit 0266e25

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ public Pair<Boolean, byte[]> execute(byte[] rawData) {
676676
byte[][] signatures = extractBytesArray(
677677
words, words[3].intValueSafe() / WORD_SIZE, rawData);
678678

679-
if (signatures.length > MAX_SIZE) {
679+
if (signatures.length == 0 || signatures.length > MAX_SIZE) {
680680
return Pair.of(true, DATA_FALSE);
681681
}
682682

@@ -825,7 +825,7 @@ private static byte[] recoverAddrBySign(byte[] sign, byte[] hash) {
825825
byte[] s;
826826
byte[] out = null;
827827
if (ArrayUtils.isEmpty(sign) || sign.length < 65) {
828-
return null;
828+
return new byte[0];
829829
}
830830
try {
831831
r = Arrays.copyOfRange(sign, 0, 32);
@@ -841,7 +841,7 @@ private static byte[] recoverAddrBySign(byte[] sign, byte[] hash) {
841841
} catch (Throwable any) {
842842
logger.info("ECRecover error", any.getMessage());
843843
}
844-
return out;//DataWord.equalAddressByteArray(address, out);
844+
return out;
845845
}
846846

847847
private static byte[][] extractBytes32Array(DataWord[] words, int offset) {
@@ -854,6 +854,9 @@ private static byte[][] extractBytes32Array(DataWord[] words, int offset) {
854854
}
855855

856856
private static byte[][] extractBytesArray(DataWord[] words, int offset, byte[] data) {
857+
if (offset > words.length - 1) {
858+
return new byte[0][];
859+
}
857860
int len = words[offset].intValueSafe();
858861
byte[][] bytesArray = new byte[len][];
859862
for (int i = 0; i < len; i++) {

0 commit comments

Comments
 (0)