@@ -48,9 +48,45 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu
4848 sevenZip = SevenZipArchive . Open ( parts , readerOptions ) ;
4949 }
5050
51- // Currently doesn't flag solid 7z archives with only 1 solid block as solid, but practically speaking
52- // this is not much of a concern.
53- if ( sevenZip . IsSolid )
51+ // Explained in https://github.com/adamhathcock/sharpcompress/pull/661. in order to determine whether
52+ // a RAR or 7Z archive is solid or not, you must check the second file in the archive, as the first
53+ // file is always marked non-solid even for solid archives. This iteration is necessary since things
54+ // like directories aren't marked solid either.
55+ // This is only temporary, as solid detection has been fixed in upstream SolidCompress, but they likely
56+ // won't make a new release for a while, and this is too big an issue to leave unfixed.
57+ bool firstFile = true ;
58+ bool isSolid = false ;
59+ foreach ( var entry in sevenZip . Entries )
60+ {
61+ try
62+ {
63+ // If the entry is a directory
64+ if ( entry . IsDirectory )
65+ continue ;
66+
67+ // If the entry has an invalid key
68+ if ( entry . Key == null )
69+ continue ;
70+
71+ // If we have a partial entry due to an incomplete multi-part archive, skip it
72+ if ( ! entry . IsComplete )
73+ continue ;
74+
75+ if ( firstFile )
76+ firstFile = false ;
77+ else
78+ {
79+ isSolid = entry . IsSolid ;
80+ break ;
81+ }
82+ }
83+ catch ( Exception ex )
84+ {
85+ if ( includeDebug ) Console . WriteLine ( ex ) ;
86+ }
87+ }
88+
89+ if ( isSolid )
5490 return ExtractSolid ( sevenZip , outputDirectory , includeDebug ) ;
5591 else
5692 return ExtractNonSolid ( sevenZip , outputDirectory , includeDebug ) ;
0 commit comments