--- old/src/java.base/share/classes/java/io/InputStream.java 2018-01-24 11:33:30.000000000 -0800 +++ new/src/java.base/share/classes/java/io/InputStream.java 2018-01-24 11:33:30.000000000 -0800 @@ -365,6 +365,10 @@ * It is strongly recommended that the stream be promptly closed if an I/O * error occurs. * + * @implNote + * The number of bytes allocated to read data from this stream and return + * the result is bounded by {@code 2*(long)len}, inclusive. + * * @param len the maximum number of bytes to read * @return a byte array containing the bytes read from this input stream * @throws IllegalArgumentException if {@code length} is negative @@ -385,7 +389,7 @@ int remaining = len; int n; do { - byte[] buf = new byte[Math.min(len, DEFAULT_BUFFER_SIZE)]; + byte[] buf = new byte[Math.min(remaining, DEFAULT_BUFFER_SIZE)]; int nread = 0; // read to EOF which may read more or less than buffer size