Files.copy(InputStream, Path, CopyOption...) can fail with OOM if direct memory is limited
Alan Bateman
Alan.Bateman at oracle.com
Sun Sep 17 15:32:42 UTC 2023
On 12/09/2023 22:39, github at paul.kungfoocoder.org wrote:
> Agreed. My question is what is the next step now that I have
> identified this problem? Do others agree that this is something that
> should be fixed? What can I do to move this forward?
>
We have to proceed with caution. You pointed to IOUtil.write in your
original mail but changing ityo limit the size of the temporary direct
buffer will likely break existing code/usage that don't correct checking
the return value. We found two cases in the JDK code and it seems likely
are more in the wider eco system. Limiting in the adaptor classes (the
classes returned by Channels.newInputStream and newOutputStream) reduces
the impact but we still need to be cautious as there may be code that
reads from an input stream and isn't checking for "short reads". For the
specific scenario here then it may be that BIS.transferTo just needs to
be changed to write chunks to the target output stream.
-Alan
More information about the nio-dev
mailing list