Uploaded image for project: 'Commons Codec'
  1. Commons Codec
  2. CODEC-265

java.lang.NegativeArraySizeException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 1.13
    • 1.14
    • None
    • Linux = Ubuntu 18.04.3 LTS

      JDK = 1.8

       

    Description

      Hi,

      trying to encode a file that is 1GB of size.

      ( linux :

      fallocate -l 1GB 1gb.zip

      )

      I want to post that file to a RESTful-service, package in JSON.

      here is the code

       

       

      String filePath = "/tmp/1gb.zip";
      System.out.println("\t Post to  : ".concat(URL));
       System.out.println("\t file : ".concat(filePath));
      Path path = Paths.get(filePath);
       byte[] bArray = Files.readAllBytes(path);
      // testing commons codec 1.16 (2019-11-05)
       byte[] encodeBase64 = Base64.encodeBase64(bArray);
      final String contentToBeSaved = new String(encodeBase64);
      HttpClient client = HttpClientBuilder.create().build();
       HttpResponse response = null;
      JSONObject metadata = new JSONObject();
       metadata.put("owner", "Ingo");
       metadata.put("access", "public");
       metadata.put("licenseType", "CC BY");
       metadata.put("fileName", "fileName");
       metadata.put("fileDataBase64", contentToBeSaved);
      String metadataFormatted = StringEscapeUtils.unescapeJavaScript(metadata.toString());
      StringEntity entity = new StringEntity(metadataFormatted, ContentType.APPLICATION_JSON);
      HttpPost post = new HttpPost(URL);
       post.setEntity(entity);
       response = client.execute(post);
       HttpEntity responseEntity = response.getEntity();
      String responseFromMediaserver = EntityUtils.toString(responseEntity, "UTF-8");
       System.out.println("\n****");
       System.out.println("Response is : " + responseFromMediaserver);
      JSONObject json = new JSONObject(responseFromMediaserver);
       String uuid = json.getString("uuid");
       System.out.println("UUID is " + uuid);
      

       

       

      1. mvn clean package
      2.   java -Xms512m -Xmx20480m -jar target/mediaClient.jar 

      The crasch is in

       

      byte[] encodeBase64 = Base64.encodeBase64(bArray);

       

      the stacktrace is :

       
      Starting NewClientEncodePost
       Post to : http://127.0.0.1:8080/MediaServerResteasy/media
       file : /tmp/1gb.zip
      Exception in thread "main" java.lang.NegativeArraySizeException
       at org.apache.commons.codec.binary.BaseNCodec.resizeBuffer(BaseNCodec.java:253)
       at org.apache.commons.codec.binary.BaseNCodec.ensureBufferSize(BaseNCodec.java:269)
       at org.apache.commons.codec.binary.Base64.encode(Base64.java:380)
       at org.apache.commons.codec.binary.BaseNCodec.encode(BaseNCodec.java:451)
       at org.apache.commons.codec.binary.BaseNCodec.encode(BaseNCodec.java:430)
       at org.apache.commons.codec.binary.Base64.encodeBase64(Base64.java:679)
       at org.apache.commons.codec.binary.Base64.encodeBase64(Base64.java:642)
       at org.apache.commons.codec.binary.Base64.encodeBase64(Base64.java:623)
       at org.apache.commons.codec.binary.Base64.encodeBase64(Base64.java:556)
       at se.nrm.bio.mediaserver.testing.base64.NewClientEncodePost.posting(NewClientEncodePost.java:55)
       at se.nrm.bio.mediaserver.testing.base64.NewClientEncodePost.main(NewClientEncodePost.java:38)
       
      

       

       

      Attachments

        1. pom.xml
          6 kB
          Ingimar
        2. Util.java
          0.8 kB
          Ingimar
        3. NewClientEncodePost.java
          3 kB
          Ingimar

        Issue Links

          Activity

            People

              aherbert Alex Herbert
              inkimar@gmail.com Ingimar
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m