Skip to content

Commit 445c161

Browse files
#372 Handle unexpected eof when reading compressed stream
1 parent 55dc47b commit 445c161

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/java/net/lingala/zip4j/util/Zip4jUtil.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ public static int readFully(InputStream inputStream, byte[] bufferToReadInto) th
132132

133133
int readLen = inputStream.read(bufferToReadInto);
134134

135+
if (readLen == -1) {
136+
throw new IOException("Unexpected EOF reached when trying to read stream");
137+
}
138+
135139
if (readLen != bufferToReadInto.length) {
136140
readLen = readUntilBufferIsFull(inputStream, bufferToReadInto, readLen);
137141

@@ -179,6 +183,13 @@ public static int readFully(InputStream inputStream, byte[] b, int offset, int l
179183

180184
private static int readUntilBufferIsFull(InputStream inputStream, byte[] bufferToReadInto, int readLength)
181185
throws IOException {
186+
if (readLength < 0) {
187+
throw new IOException("Invalid readLength");
188+
}
189+
190+
if (readLength == 0) {
191+
return 0;
192+
}
182193

183194
int remainingLength = bufferToReadInto.length - readLength;
184195
int loopReadLength = 0;

0 commit comments

Comments
 (0)