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

ZipArchiveInputStream doesn't report the end of a truncated archive

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.0, 1.1
    • Fix Version/s: 1.1
    • Component/s: None
    • Labels:
      None

      Description

      If a Zip archive is truncated, (e.g. because it is the first volume in a multi-volume archive) the ZipArchiveInputStream.read() method will not detect that fact. All calls to read() will return 0 bytes read. They will not return -1 (end of stream), nor will they throw any exception (which would seem like a good idea to me because the archive is truncated).

      I have tracked this problem to ZipArchiveInputStream.java, line 239. It contains a check

      if (read == 0 && inf.finished()) {
      return -1;
      }

      For truncated archives the read is always zero but the inf is never finished(). I suggest adding two lines below:

      if (read == 0 && inf.finished()) {
      return -1;
      } else if (read == 0 && lengthOfLastRead == -1) {
      throw new IOException("Truncated ZIP file");
      }

      This solves the problem in my tests.

        Attachments

        1. commons-compress-87.patch
          5 kB
          Antoni Mylka
        2. apache-maven-2.2.1.zip.001
          64 kB
          Antoni Mylka

          Issue Links

            Activity

              People

              • Assignee:
                bodewig Stefan Bodewig
                Reporter:
                antheque Antoni Mylka
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: