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

Base64.Encoder incorrectly throws NegativeArraySizeException

    XMLWordPrintable

Details

    • b06
    • generic
    • generic
    • Verified

    Description

      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)

      Attachments

        Issue Links

          Activity

            People

              nishjain Nishit Jain
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: