Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8217969

Base64.Decoder.decode methods do not need to throw OOME due to integer overflow

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 13
    • Fix Version/s: 13
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Introduced In Version:
      13
    • Resolved In Build:
      b07
    • Verification:
      Verified

      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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                nishjain Nishit Jain
                Reporter:
                nishjain Nishit Jain
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: