RFR: 6478546: FileInputStream.read() throws OutOfMemoryError when there is plenty available

Alan Bateman alanb at openjdk.org
Mon Jul 24 13:19:42 UTC 2023


On Fri, 21 Jul 2023 22:40:00 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> Limit native memory allocation and move write loop from the native layer into Java. This change should make the OOME reported in the issue much less likely.

src/java.base/share/classes/java/io/FileOutputStream.java line 366:

> 364:                 int n = writeBytes(b, off, len, append);
> 365:                 if (n == -1)
> 366:                     break;

Checking if n is -1 doesn't look right here. Isn't return -1 just to keep the compiler happy when an exception is thrown.

src/java.base/share/native/libjava/io_util.c line 62:

> 60: /* The maximum size of a dynamically-allocated buffer.
> 61:  */
> 62: #define MAX_MALLOC_SIZE 2097152

How did you choose 2Mb, it seems high.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14981#discussion_r1272230776
PR Review Comment: https://git.openjdk.org/jdk/pull/14981#discussion_r1272250651


More information about the security-dev mailing list