diff --git a/dexlib2/src/main/java/org/jf/dexlib2/util/Preconditions.java b/dexlib2/src/main/java/org/jf/dexlib2/util/Preconditions.java index faf9fd2b..e5745846 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/util/Preconditions.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/util/Preconditions.java @@ -220,13 +220,13 @@ public class Preconditions { } public static > L checkArrayPayloadElements(int elementWidth, L elements) { - // mask of all bits that do not fit into an 'elementWidth'-bit number - long bitmask = -1L << elementWidth; + // mask of all bits that do not fit into an 'elementWidth'-byte number + long bitmask = -1L << (elementWidth * 8); for (Number element : elements) { if ((element.longValue() & bitmask) != 0) { throw new IllegalArgumentException( - String.format("Number %d must fit into a %d-bit number", element.longValue(), elementWidth)); + String.format("Number %d must fit into a %d-byte number", element.longValue(), elementWidth)); } } diff --git a/dexlib2/src/test/java/org/jf/util/PreconditionsTest.java b/dexlib2/src/test/java/org/jf/util/PreconditionsTest.java new file mode 100644 index 00000000..08d02e19 --- /dev/null +++ b/dexlib2/src/test/java/org/jf/util/PreconditionsTest.java @@ -0,0 +1,23 @@ +package org.jf.util; + +import java.util.ArrayList; +import java.util.List; +import org.jf.dexlib2.Opcode; +import org.jf.dexlib2.iface.instruction.formats.ArrayPayload; +import org.jf.dexlib2.util.Preconditions; +import org.junit.Assert; +import org.junit.Test; + +public class PreconditionsTest { + + @Test + public void checkArrayPayloadElements() { + int intSize = 4; + int bigNumber = 16843071; + List numbers = new ArrayList<>(); + numbers.add(bigNumber); + + // Shouldn't throw any exceptions, payload is correct. + Preconditions.checkArrayPayloadElements(intSize, numbers); + } +}