Commons Compress
  1. Commons Compress
  2. COMPRESS-227

duplicate entries may let ZipFile#getInputStream return null

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: 1.6
    • Component/s: Archivers
    • Labels:

      Description

      Found while investigating https://issues.apache.org/bugzilla/show_bug.cgi?id=54967

      If an archive contains two entries for the same file readCentralDirectory in ZipFile will only add the first entry to the entries map and only the last to the nameMap map - this is because entries is a LinkedHashMap and nameMap is a "plain" HashMap.

      Normally this wouldn't matter since both ZipArchiveEntry instances are equal and thus it is irrelevant which of the two is used as a key when obtaining the InputStream.

      Things get different, though, if the entry has data inside the local file header as only the first entry is dealt with in resolveLocalFileHeaderData - after this the two instances are no longer equal and nameMap.get(NAME) will return an instance that can no longer be found.

      I intend to modify readCentralDirectory to only add the first entry to nameMap as well and document the behavior. I'll also start a discussion thread on the dev list on whether we need to provide an additional API with multiple entries per name.

      1. test.zip
        0.2 kB
        Stefan Bodewig

        Activity

        Stefan Bodewig created issue -
        Hide
        Stefan Bodewig added a comment -

        One way to fix it is committed with svn revision 1484499

        Show
        Stefan Bodewig added a comment - One way to fix it is committed with svn revision 1484499
        Hide
        Stefan Bodewig added a comment -

        Test archive containing the same (empty) entry twice

        Show
        Stefan Bodewig added a comment - Test archive containing the same (empty) entry twice
        Stefan Bodewig made changes -
        Field Original Value New Value
        Attachment test.zip [ 12583988 ]
        Hide
        Sebb added a comment -

        The test archive shows 2 entries in both WinZip (9.0) and 7-Zip (9.20).

        Show
        Sebb added a comment - The test archive shows 2 entries in both WinZip (9.0) and 7-Zip (9.20).
        Hide
        Stefan Bodewig added a comment -

        svn revision 1486348 adds two methods to ZipFile that provide access to all entries of a given name.

        Show
        Stefan Bodewig added a comment - svn revision 1486348 adds two methods to ZipFile that provide access to all entries of a given name.
        Stefan Bodewig made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Stefan Bodewig
            Reporter:
            Stefan Bodewig
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development