This was discovered as part of my work on #560
AES/CFB/NoPadding will incorrectly throw IllegalArgumentException when the no-argument doFinal() method is called because this implicitly calls engineDoFinal(byte[], int, int, byte[], int) with a null input array. That is then passed directly to Utils.checkArrayLimits() which requires the array to be non-null.
Repro:
import java.security.Security;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider;
public class CfbEmptyDoFinalRepro {
public static void main(String[] args) throws Exception {
Security.insertProviderAt(AmazonCorrettoCryptoProvider.INSTANCE, 1);
Cipher cipher = Cipher.getInstance("AES/CFB/NoPadding", "AmazonCorrettoCryptoProvider");
cipher.init(
Cipher.ENCRYPT_MODE,
new SecretKeySpec(new byte[16], "AES"),
new IvParameterSpec(new byte[16]));
byte[] result = cipher.doFinal(); // no-arg doFinal: JDK passes a null input array to the SPI
System.out.println("doFinal() returned " + result.length + " bytes");
}
}
Expected output:
doFinal() returned 0 bytes
Actual output:
Exception in thread "main" java.lang.IllegalArgumentException: Bad argument: bytes cannot be null.
at com.amazon.corretto.crypto.provider.Utils.checkArrayLimits(Utils.java:574)
at com.amazon.corretto.crypto.provider.AesCfbSpi.engineDoFinal(AesCfbSpi.java:248)
at com.amazon.corretto.crypto.provider.AesCfbSpi.engineDoFinal(AesCfbSpi.java:233)
at java.base/javax.crypto.Cipher.doFinal(Cipher.java:2103)
This was discovered as part of my work on #560
AES/CFB/NoPaddingwill incorrectly throwIllegalArgumentExceptionwhen the no-argumentdoFinal()method is called because this implicitly callsengineDoFinal(byte[], int, int, byte[], int)with anullinput array. That is then passed directly to Utils.checkArrayLimits() which requires the array to be non-null.Repro:
Expected output:
Actual output: