JDK-8321053 : Use ByteArrayInputStream.buf directly when parameter of transferTo() is trusted
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 11,17,21,22
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2023-11-29
  • Updated: 2025-04-30
  • Resolved: 2023-12-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 22
22 b27Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
The internal array of bytes in ByteArrayInputStream should be passed to the OutputStream parameter of ByteArrayInputStream.transferTo(OutputStream) only if the latter is in the package java.io.
Comments
[21u backport comment] Hi [~thu], this potentially increases memory consumption which can affect GC, an applications memory need, pause times and runtime. This is a central class. Together, i would not rate the risk as low. Nevertheless the issue seems worth while fixing to me. I succesfully ran this through our testing.
30-04-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk21u-dev/pull/1669 Date: 2025-04-16 18:35:40 +0000
16-04-2025

[jdk21u-fix-request] Approval Request from Daniel Hu Fixes bug with ByteArrayInputStream.transferTo passing internal buf to non java.io OutputStream. Applies cleanly. Patched in JDK22, and no known bugs from this change. New test fails without the fix, and passes with it. Risk is low given the length of time in mainline and minor change.
16-04-2025

AFAICS, this is a long-standing issue introduced by JDK-8180451.
07-12-2023

Changeset: b0d14509 Author: Brian Burkhalter <bpb@openjdk.org> Date: 2023-12-05 19:41:12 +0000 URL: https://git.openjdk.org/jdk/commit/b0d145097cdc61e4bab19393a125e63aa3bc29b9
05-12-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/16893 Date: 2023-11-30 00:03:21 +0000
30-11-2023