Radek Kraus created COMPRESS-664:
------------------------------------
Summary: Prevent to throw ZipException from
ZipArchiveInputStream.getNextEnry() for empty file
Key: COMPRESS-664
URL: https://issues.apache.org/jira/browse/COMPRESS-664
Project: Commons Compress
Issue Type: Bug
Components: Archivers
Affects Versions: 1.26.0
Reporter: Radek Kraus
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.
{code:java}
@Test
public void testGetFirstEntryEmptyZip_Java() throws IOException {
try (ZipInputStream zin = new ZipInputStream(new ByteArrayInputStream(new
byte[0]))) {
ZipEntry entry = zin.getNextEntry();
assertNull(entry);
}
}
{code}
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:
The key is to don't catch {{EOFException}} and transform it into
{{{}ZipException{}}}, but simply throw it into
{{ZipArchiveInputStream.getNextZipEntry()}} method, when 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.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)