RFR: 8254742: InputStream::readNBytes(int) result may contain zeros not in input
Brent Christian
bchristi at openjdk.java.net
Wed Nov 4 00:54:57 UTC 2020
On Tue, 3 Nov 2020 00:04:58 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
> InputStream::readNBytes() invokes read(byte[],int,int) repeatedly to load bytes into a sequence of intermediate arrays. If an intermediate array is not completely filled before being added to the list of arrays the contents of which are eventually concatenated to produce the result, then the unfilled part of the intermediate array will contribute zeros to the result which are not actually in the input. This can occur for example if n < 8192 bytes are read into an intermediate array without filling it, and the next read() returns zero. It is proposed to detect when an intermediate array is only partially full, and to copy the valid range of the array into a new array which is instead appended to the list of component arrays.
Marked as reviewed by bchristi (Reviewer).
-------------
PR: https://git.openjdk.java.net/jdk/pull/1024
More information about the core-libs-dev
mailing list