-
Bug
-
Resolution: Fixed
-
P4
-
9, 11, 12
-
b06
-
generic
-
generic
-
Verified
ADDITIONAL SYSTEM INFORMATION :
openjdk version "11-ea" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11-ea+26)
OpenJDK 64-Bit Server VM 18.9 (build 11-ea+26, mixed mode)
A DESCRIPTION OF THE PROBLEM :
Base64.Encoder incorrectly handles arrays of sizes that approach Integer.MAX_VALUE. Due to a bug in the implementation, a NegativeArraySizeException may be thrown during encoding. Instead, it should either complete the encoding successfully, or throw an OutOfMemoryError.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
launch jshell:
jshell -R-Xmx8G
and execute the following 2 commands (the first will take quite some time):
byte[] input = new byte[Integer.MAX_VALUE-2];
byte[] output = Base64.getEncoder().encode(input);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Either no exception occurs, or an OutOfMemoryError is thrown
ACTUAL -
| Exception java.lang.NegativeArraySizeException: -1431655768
| at Base64$Encoder.encode (Base64.java:265)
| at (#6:1)
openjdk version "11-ea" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11-ea+26)
OpenJDK 64-Bit Server VM 18.9 (build 11-ea+26, mixed mode)
A DESCRIPTION OF THE PROBLEM :
Base64.Encoder incorrectly handles arrays of sizes that approach Integer.MAX_VALUE. Due to a bug in the implementation, a NegativeArraySizeException may be thrown during encoding. Instead, it should either complete the encoding successfully, or throw an OutOfMemoryError.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
launch jshell:
jshell -R-Xmx8G
and execute the following 2 commands (the first will take quite some time):
byte[] input = new byte[Integer.MAX_VALUE-2];
byte[] output = Base64.getEncoder().encode(input);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Either no exception occurs, or an OutOfMemoryError is thrown
ACTUAL -
| Exception java.lang.NegativeArraySizeException: -1431655768
| at Base64$Encoder.encode (Base64.java:265)
| at (#6:1)
- csr for
-
JDK-8215633 Base64.Encoder.encode and Base64.Decoder.decode should specify OOME if the output bytes array/buffer of the needed size can not be allocated
- Closed
- relates to
-
JDK-8218265 java/util/Base64/TestEncodingDecodingLength.java failing
- Closed
-
JDK-8217969 Base64.Decoder.decode methods do not need to throw OOME due to integer overflow
- Closed