8254742: InputStream::readNBytes(int) result may contain zeros not in input

Reviewed-by: shade, bchristi
This commit is contained in:
Brian Burkhalter 2020-11-04 16:50:02 +00:00
parent 7dcaba6312
commit c287170c94
2 changed files with 42 additions and 4 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -416,6 +416,9 @@ public abstract class InputStream implements Closeable {
if (MAX_BUFFER_SIZE - total < nread) {
throw new OutOfMemoryError("Required array size too large");
}
if (nread < buf.length) {
buf = Arrays.copyOfRange(buf, 0, nread);
}
total += nread;
if (result == null) {
result = buf;