Uploaded image for project: 'Commons Compress'
  1. Commons Compress
  2. COMPRESS-664

Prevent to throw ZipException from ZipArchiveInputStream.getNextEntry() for empty file

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.26.0
    • 1.26.1
    • Archivers
    • None

    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:

      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

          Activity

            People

              Unassigned Unassigned
              rkraus Radek Kraus
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: