mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-12 17:03:14 +00:00
8139706: JarFile.getBytes could use InputStream.readNBytes
Reviewed-by: sherman, chegar, alanb
This commit is contained in:
parent
ef3d646119
commit
e3d1fffbe4
@ -438,10 +438,19 @@ class JarFile extends ZipFile {
|
||||
private byte[] getBytes(ZipEntry ze) throws IOException {
|
||||
try (InputStream is = super.getInputStream(ze)) {
|
||||
int len = (int)ze.getSize();
|
||||
byte[] b = is.readAllBytes();
|
||||
if (len != -1 && b.length != len)
|
||||
throw new EOFException("Expected:" + len + ", read:" + b.length);
|
||||
|
||||
int bytesRead;
|
||||
byte[] b;
|
||||
// trust specified entry sizes when reasonably small
|
||||
if (len != -1 && len <= 65535) {
|
||||
b = new byte[len];
|
||||
bytesRead = is.readNBytes(b, 0, len);
|
||||
} else {
|
||||
b = is.readAllBytes();
|
||||
bytesRead = b.length;
|
||||
}
|
||||
if (len != -1 && len != bytesRead) {
|
||||
throw new EOFException("Expected:" + len + ", read:" + bytesRead);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user