-
Type:
CSR
-
Resolution: Unresolved
-
Priority:
P4
-
Component/s: security-libs
-
None
-
minimal
-
It is unlikely that programs were setting the offset parameter to a negative number while catching an ArrayIndexOutOfBoundsException.
-
Java API
Summary
When a negative offset is passed to the java.base/javax.crypto.spec.DESKeySpec.isWeak method the method should check for this condition and throw an InvalidKeyException when the parameter is negative.
Problem
Currently the signage of the offset parameter is not checked before continuing to calculate byte offset of the targeted DES key. Therefore a ArrayIndexOutOfBoundsException is thrown when the method tries to index the byte array at the negative offset. Throwing an array index bounds exception does not adhere to good programming practices.
Solution
The solution is to check that the offset is or is not negative. If negative then the InvalidKeyException will be thrown instead.
Specification
src/java.base/share/classes/javax/crypto/spec/DESKeySpec.java:
@@ -219,10 +219,13 @@
public static boolean isWeak(byte[] key, int offset)
throws InvalidKeyException {
if (key == null) {
throw new InvalidKeyException("null key");
}
+ if (offset < 0) {
+ throw new InvalidKeyException("invalid offset");
+ }
if (key.length - offset < DES_KEY_LEN) {
throw new InvalidKeyException("Wrong key size");
}
for (int i = 0; i < WEAK_KEYS.length; i++) {
boolean found = true;
- csr of
-
JDK-8364121 DESKeySpec.isWeak does not check negative offset
-
- Open
-