Make ZipHeaderInputStream read sub 5 byte entries correctly

Closes gh-13525
This commit is contained in:
Andy Wilkinson
2018-06-19 16:44:08 +01:00
parent 99f993bc82
commit 6081db5c34
2 changed files with 67 additions and 7 deletions

View File

@@ -357,15 +357,15 @@ public class JarWriter implements LoaderClassesWriter {
public int read(byte[] b, int off, int len) throws IOException {
int read = (this.headerStream != null ? this.headerStream.read(b, off, len)
: -1);
if (read > 0) {
this.position += read;
}
else {
read = 0;
if (read <= 0) {
return readRemainder(b, off, len);
}
this.position += read;
if (read < len) {
read += super.read(b, off + read, len - read);
this.position += read;
int remainderRead = readRemainder(b, off + read, len - read);
if (remainderRead > 0) {
read += remainderRead;
}
}
if (this.position >= this.headerLength) {
this.headerStream = null;
@@ -377,6 +377,14 @@ public class JarWriter implements LoaderClassesWriter {
return Arrays.equals(this.header, ZIP_HEADER);
}
private int readRemainder(byte[] b, int off, int len) throws IOException {
int read = super.read(b, off, len);
if (read > 0) {
this.position += read;
}
return read;
}
}
/**