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.
------------- Commit messages: - 8254742: InputStream::readNBytes(int) result may contain zeros not in input Changes: https://git.openjdk.java.net/jdk/pull/1024/files Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=1024&range=00 Issue: https://bugs.openjdk.java.net/browse/JDK-8254742 Stats: 43 lines in 2 files changed: 39 ins; 1 del; 3 mod Patch: https://git.openjdk.java.net/jdk/pull/1024.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/1024/head:pull/1024 PR: https://git.openjdk.java.net/jdk/pull/1024