Skip to content

Commit

Permalink
Added guard for negative numbers in LEB128U.encode
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusbechwind committed Mar 13, 2024
1 parent e01f20e commit 53ba9ce
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ public static byte[] encode(BigInteger value) {
* @param value {@link BigInteger} representing the value to encode.
* @param maxSize the max amount of bytes to decode.
* @return byte array containing the encoded value.
* @throws IllegalArgumentException if more than `maxSize` bytes are encoded.
* @throws IllegalArgumentException if more than `maxSize` bytes are encoded or `value` is negative.
*/
public static byte[] encode(BigInteger value, int maxSize) {

if (value.compareTo(BigInteger.ZERO) < 0) {
throw new IllegalArgumentException("Cannot encode negative amount: " + value);
}
if (value.equals(BigInteger.ZERO)) {
return new byte[]{0};
}
Expand Down

0 comments on commit 53ba9ce

Please sign in to comment.