You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Ion Moldovan (JIRA)" <ji...@apache.org> on 2018/02/09 10:45:04 UTC

[jira] [Created] (HTTPCORE-513) ExpandableBuffer breaks on large response

Ion Moldovan created HTTPCORE-513:
-------------------------------------

             Summary: ExpandableBuffer breaks on large response
                 Key: HTTPCORE-513
                 URL: https://issues.apache.org/jira/browse/HTTPCORE-513
             Project: HttpComponents HttpCore
          Issue Type: Bug
          Components: HttpCore, HttpCore NIO
    Affects Versions: 4.4.9
            Reporter: Ion Moldovan


Steps:
 # create a PHP page with the following content: 
 ## <?php
$response='abc';
echo str_pad($response, 2147483647);
 # send a request using jMeter to the said page

Expected result: the request is received

Actual result: the VM fails with:

java.lang.OutOfMemoryError: Requested array size exceeds VM limit
Dumping heap to java_pid20344.hprof ...
Heap dump file created [3275879706 bytes in 7.490 secs]
Uncaught Exception java.lang.OutOfMemoryError: Requested array size exceeds VM limit. See log file for details.

 

Proposed solution:
 * rewrite org.apache.http.nio.util.ExpandableBuffer.expand() to:
 ** /**
 * Expands buffer's capacity.
 */
 protected void expand() {
 int newcapacity = (this.buffer.capacity() + 1) << 1;
 if (newcapacity < 0) {
 int headRoom = Integer.max(Long.BYTES, 8);
 // Long has the longest header available. Object header seems to be linked to it. Equals the number of bits of the platform.
 // I added a minimum of 8 (it is used in ArrayList: private static final int MAX_ARRAY_SIZE = 2147483639;)
 // WARNING: This code assumes you are providing enough heap room with -Xmx.
 // source of inspiration: https://bugs.openjdk.java.net/browse/JDK-8059914
 
 newcapacity = Integer.MAX_VALUE - headRoom;
 }
 expandCapacity(newcapacity);
 }

 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org