8280409: JarFile::getInputStream can fail with NPE accessing ze.getName()

Reviewed-by: mullan, alanb
This commit is contained in:
Lance Andersen 2022-02-23 16:56:50 +00:00
parent 99b8ed9dbf
commit a020b6ba8f
3 changed files with 1103 additions and 32 deletions

View file

@ -345,7 +345,8 @@ public class ZipFile implements ZipConstants, Closeable {
*
* @param entry the zip file entry
* @return the input stream for reading the contents of the specified
* zip file entry.
* zip file entry or null if the zip file entry does not exist
* within the zip file.
* @throws ZipException if a ZIP format error has occurred
* @throws IOException if an I/O error has occurred
* @throws IllegalStateException if the zip file has been closed
@ -368,28 +369,28 @@ public class ZipFile implements ZipConstants, Closeable {
}
in = new ZipFileInputStream(zsrc.cen, pos);
switch (CENHOW(zsrc.cen, pos)) {
case STORED:
synchronized (istreams) {
istreams.add(in);
}
return in;
case DEFLATED:
// Inflater likes a bit of slack
// MORE: Compute good size for inflater stream:
long size = CENLEN(zsrc.cen, pos) + 2;
if (size > 65536) {
size = 8192;
}
if (size <= 0) {
size = 4096;
}
InputStream is = new ZipFileInflaterInputStream(in, res, (int)size);
synchronized (istreams) {
istreams.add(is);
}
return is;
default:
throw new ZipException("invalid compression method");
case STORED:
synchronized (istreams) {
istreams.add(in);
}
return in;
case DEFLATED:
// Inflater likes a bit of slack
// MORE: Compute good size for inflater stream:
long size = CENLEN(zsrc.cen, pos) + 2;
if (size > 65536) {
size = 8192;
}
if (size <= 0) {
size = 4096;
}
InputStream is = new ZipFileInflaterInputStream(in, res, (int) size);
synchronized (istreams) {
istreams.add(is);
}
return is;
default:
throw new ZipException("invalid compression method");
}
}
}