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

ZipArchiveInputStream may read incorrect bytes from stream when processing nested ZIP

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Invalid
    • 1.5
    • 1.6
    • Archivers

    Description

      The problem is relevant to COMPRESS-189, in particular it relates to processing of inner ZIP files.

      Problem description:

      If the archive entry is not fully read, then partial reading returns incorrect contents.

      In particular the given example loops trough all entries of "09815141_4.zip" ZIP archive, probing each entry to be a TIFF file. The probe assumes that given file is TIFF, if it starts with bytes [0x49 0x49 0x2A 0x0 0x8 0x0 0x0 0x0 0x14 0x0].

      Most entries are correctly reported as TIFF, except:

      [ArchiveTest] 000017.tif is something else
      [ArchiveTest] Header contents: 0x49 0x49 0x2A 0x0 0x8 0x0 0x0 0x0 0x0 0x0 
      [ArchiveTest] 000033.tif is something else
      [ArchiveTest] Header contents: 0x49 0x49 0x2A 0x0 0x0 0x0 0x0 0x0 0x0 0x0 
      [ArchiveTest] 000056.tif is something else
      [ArchiveTest] Header contents: 0x49 0x49 0x2A 0x0 0x8 0x0 0x0 0x0 0x0 0x0 
      [ArchiveTest] 000069.tif is something else
      [ArchiveTest] Header contents: 0x49 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 
      

      As I can see, the problem can be introduced at any random byte.

      If the program is set READ_WHOLE_ENTRY=true then all entries are fully read and MD5 sum is calculated. MD5 sum matches and all entries are correctly reported as TIFF. Thus the problem is only present when entry is not fully read and ArchiveInputStream.getNextEntry() is called.

      Test ZIP can be downloaded from: https://www.dropbox.com/s/h20wo6t0mwbgsqc/09815141_4.zip
      It was originally taken from WIPO FTP (i.e. it is in public domain) and was a bit stripped.

      Difficult to say what is the impact of this bug, but for 475 ZIP-in-ZIPs in my collection I have found 3 examples of incorrect contents extraction.

      Attachments

        1. ArchiveTest.java
          3 kB
          Stefan Bodewig
        2. ArchiveTest.java
          3 kB
          Dmitry Katsubo
        3. log_read_whole_entry.txt
          9 kB
          Dmitry Katsubo
        4. log.txt
          4 kB
          Dmitry Katsubo
        5. md5.correct.txt
          3 kB
          Dmitry Katsubo

        Activity

          People

            Unassigned Unassigned
            dma_k Dmitry Katsubo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: