JDK-8217969 : Base64.Decoder.decode methods do not need to throw OOME due to integer overflow
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 13
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2019-01-29
  • Updated: 2019-04-03
  • Resolved: 2019-02-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 13
13 b07Fixed
Related Reports
CSR :  
Relates :  
Description
As mentioned in the JDK-8210583 bug description about Base64.Encoder.encode throwing NegativeArraySizeException, the Base64.Decoder.decode method was also throwing NegativeArraySizeException while decoding the large arrays near Integer.MAX_VALUE, which is only because of the intermediate result integer overflow while computing the decoded output length, not the final result.

Instead of throwing OOME (as done by JDK-8210583 fix), the NegativeArraySizeException issue could have been resolved by storing that intermediate result with larger type "long" and then converting the final result to integer. So there is not need for OOME due to overflow as it does not happen with final result.


byte[] input = new byte[Integer.MAX_VALUE-2];
byte[] output = Base64.getDecoder().decode(input);

The above snippet throws OOME ("Decoded size is too large") even if the output length is less than Integer.MAX_VALUE