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

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 13
    • 13
    • core-libs
    • 13
    • b07
    • 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

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

              Dates

                Created:
                Updated:
                Resolved: