RFR: 8371718: (sc) Channels.new{Input, Output}Stream can allocate unbounded memory for a socket channel

Alan Bateman alanb at openjdk.org
Mon Dec 8 19:24:07 UTC 2025


On Mon, 8 Dec 2025 19:10:42 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> Clamp read and write to 128k bytes.

src/java.base/share/classes/sun/nio/ch/ChannelInputStream.java line 86:

> 84:         if (bb.remaining() > MAX_ADAPTOR_BUFFER_SIZE) {
> 85:             bb = bb.slice(bb.position(), MAX_ADAPTOR_BUFFER_SIZE);
> 86:         }

I think we should limit the length in `read(byte[] bs, int off, int len)`.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28705#discussion_r2599838951


More information about the nio-dev mailing list