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

Corrupt 7z allocates huge amount of SevenZEntries

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.20
    • 1.21
    • None
    • None

    Description

      We ran into a problem where a 1.43GB corrupt 7z file tried to allocate about 138 million SevenZArchiveEntries which will use about 12GB of memory. Sadly I'm unable to share the file. If you have enough Memory available the following exception is thrown.

      java.io.IOException: Start header corrupt and unable to guess end Header
      	at org.apache.commons.compress.archivers.sevenz.SevenZFile.tryToLocateEndHeader(SevenZFile.java:511)
      	at org.apache.commons.compress.archivers.sevenz.SevenZFile.readHeaders(SevenZFile.java:470)
      	at org.apache.commons.compress.archivers.sevenz.SevenZFile.<init>(SevenZFile.java:336)
      	at org.apache.commons.compress.archivers.sevenz.SevenZFile.<init>(SevenZFile.java:128)
      	at org.apache.commons.compress.archivers.sevenz.SevenZFile.<init>(SevenZFile.java:369)
      
      

      7z itself aborts really quick when I'm trying to list the content of the file.

      7z l "corrupt.7z"
      
      7-Zip 18.01 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2018-01-28
      
      Scanning the drive for archives:
      1 file, 1537752212 bytes (1467 MiB)
      
      Listing archive: corrupt.7z
      
      ERROR: corrupt.7z : corrupt.7z
      Open ERROR: Can not open the file as [7z] archive
      
      ERRORS:
      Is not archive
      
      Errors: 1
      

      I hacked together the attached patch which will reduce the memory allocation to about 1GB. So lazy instantiation of the entries could be a good solution to the problem. Optimal would be to only create the entries if the headers could be parsed correctly.

      Attachments

        1. Reduced_memory_allocation_for_corrupted_7z_archives.patch
          4 kB
          Robin Schimpf
        2. endheadercorrupted2.7z
          0.2 kB
          A Kelday
        3. endheadercorrupted.7z
          0.2 kB
          A Kelday

        Issue Links

          Activity

            People

              Unassigned Unassigned
              rschimpf Robin Schimpf
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 3h 10m
                  3h 10m