< prev index next >

src/java.base/share/classes/java/util/jar/JarVerifier.java

Print this page
8206863: A closed JarVerifier.VerifierStream should throw IOException
Reviewed-by: rasbold
Contributed-by: Tobias Thierer <tobiast@google.com>, Martin Buchholz <martinrb@google.com>

*** 435,455 **** VerifierStream(Manifest man, JarEntry je, InputStream is, JarVerifier jv) throws IOException { ! this.is = is; this.jv = jv; this.mev = new ManifestEntryVerifier(man); this.jv.beginEntry(je, mev); this.numLeft = je.getSize(); if (this.numLeft == 0) this.jv.update(-1, this.mev); } public int read() throws IOException { if (numLeft > 0) { int b = is.read(); jv.update(b, mev); numLeft--; if (numLeft == 0) --- 435,456 ---- VerifierStream(Manifest man, JarEntry je, InputStream is, JarVerifier jv) throws IOException { ! this.is = Objects.requireNonNull(is); this.jv = jv; this.mev = new ManifestEntryVerifier(man); this.jv.beginEntry(je, mev); this.numLeft = je.getSize(); if (this.numLeft == 0) this.jv.update(-1, this.mev); } public int read() throws IOException { + ensureOpen(); if (numLeft > 0) { int b = is.read(); jv.update(b, mev); numLeft--; if (numLeft == 0)
*** 459,468 **** --- 460,470 ---- return -1; } } public int read(byte b[], int off, int len) throws IOException { + ensureOpen(); if ((numLeft > 0) && (numLeft < len)) { len = (int)numLeft; } if (numLeft > 0) {
*** 486,498 **** --- 488,506 ---- mev = null; jv = null; } public int available() throws IOException { + ensureOpen(); return is.available(); } + private void ensureOpen() throws IOException { + if (is == null) { + throw new IOException("stream closed"); + } + } } // Extended JavaUtilJarAccess CodeSource API Support private Map<URL, Map<CodeSigner[], CodeSource>> urlToCodeSourceMap = new HashMap<>();
< prev index next >