Skip to content

Commit

Permalink
#371 Handle unexpected eof when reading stream
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-lingala committed Mar 22, 2022
1 parent 5b3c43b commit 55dc47b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public int readRawFully(byte[] b) throws IOException {

int readLen = inputStream.read(b);

if (readLen == -1) {
throw new IOException("Unexpected EOF reached when trying to read stream");
}

if (readLen != b.length) {
readLen = readUntilBufferIsFull(b, readLen);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,15 @@ public void testExtractZipFileWithInvalidAesExtraDataRecordThrowsException() thr
null, InternalZipConstants.BUFF_SIZE, false, 1);
}

@Test
public void testExtractZipFileWhenUnexpectedEofReachedThrowsException() throws IOException {
expectedException.expect(IOException.class);
expectedException.expectMessage("Unexpected EOF reached when trying to read stream");

extractZipFileWithInputStreams(TestUtils.getTestArchiveFromResources("unexpected-eof-when-reading-stream"),
null, InternalZipConstants.BUFF_SIZE, false, 1);
}

private void extractZipFileWithInputStreams(File zipFile, char[] password) throws IOException {
extractZipFileWithInputStreams(zipFile, password, InternalZipConstants.BUFF_SIZE);
}
Expand Down
Binary file not shown.

0 comments on commit 55dc47b

Please sign in to comment.