Description
The version 1.26.0 (regression against 1.25.0) changes behavior of ZipArchiveInputStream.getNextEntry() for empty file (zero size). Currently ZipException("Cannot find zip signature within the file") is thrown instead of return null value, when first entry is requested.
This was caused by:
- https://github.com/apache/commons-compress/pull/471 (Support preamble garbage in ZipArchiveInputStream)
- https://github.com/apache/commons-compress/commit/7d2fde71046c31508483ca80abbdfcdb4d5c78b9
I guess it is a really regression error, because I don't see a reason why ZipException should be thrown, even when zip can ignore any garbage at the beginning of file up to certain size.
The standard java ZipInputStream implementation returns null value too, when java.util.zip.ZipInputStream.getNextEntry() is invoked.
@Test public void testGetFirstEntryEmptyZip_Java() throws IOException { try (ZipInputStream zin = new ZipInputStream(new ByteArrayInputStream(new byte[0]))) { ZipEntry entry = zin.getNextEntry(); assertNull(entry); } }
I guess commons-compress 1.26.0 (ZipArchiveInputStream) should preserve the same behavior like in version 1.25.0 and like java ZipInputStream.
Here is my PR with simple change: https://github.com/apache/commons-compress/pull/486
The key is to don't catch EOFException and transform it into ZipException, but simply throw it into ZipArchiveInputStream.getNextZipEntry() method, where null value is returned (like in case of second and next entries).
Please check/review PR deeply, because I don't understand the complex way how "Garbage" is skipped in ZipArchiveInputStream.readFirstLocalFileHeader() method.
Attachments
Issue Links
- links to