You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2019/11/26 15:20:50 UTC

[GitHub] [commons-codec] aherbert opened a new pull request #30: [CODEC-265] BaseNCodec to expand buffer using overflow conscious code.

aherbert opened a new pull request #30: [CODEC-265] BaseNCodec to expand buffer using overflow conscious code.
URL: https://github.com/apache/commons-codec/pull/30
 
 
   Re: [CODEC-265] Add a test to encode a 1 Gigabyte byte[].
   
   Added overflow conscious code for buffer expansion during encoding and decoding. This is based on java.util.ArrayList but modified to use a local copy of JDK 1.8 Integer.compareUnsigned(int, int) to compare the new buffer capacity to the required capacity.
       
   Unlike the java.util.ArrayList if the minCapacity exceeds the head room for the maximum array size, the capacity returned is the required minCapacity and not Integer.MAX_VALUE. This allows the test `testEnsureBufferSizeExpandsToBeyondMaxBufferSize` to pass on my machine using:
   
   ```
   java -version
   openjdk version "1.8.0_222"
   OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~16.04.1-b10)
   OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
   ``` 
   
   If I return Integer.MAX_VALUE for the new capacity then the test fails as my machine cannot allocate arrays of this size. This test has an assume method that tries to allocate the very large raw byte array. If this is not possible then the test is skipped.
   
   This fix allows reinstating Base64 HugeLineSeparator test as the buffer expansion ensures that the minimum allowed capacity is allocated even if doubling the buffer size is not enough.
   
   Note:
   
   The test for allocating the maximum buffer size requires >2GB of RAM. The test for encoding a 1 GB file requires >3GB of RAM. The tests attempt to detect the amount of RAM that can be allocated and skip if necessary. Travis does not run the test for encoding a 1GB file as it does not have 3GB of memory.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services