@@ -84,20 +84,17 @@ public override bool Execute()
84
84
if ( isZipArchive )
85
85
{
86
86
using var zip = new ZipArchive ( File . OpenRead ( SourceArchive ) ) ;
87
+ string fullDestDirPath = GetFullDirectoryPathWithSeperator ( DestinationDirectory ) ;
88
+
87
89
foreach ( var entry in zip . Entries )
88
90
{
89
91
if ( ShouldExtractItem ( entry . FullName ) )
90
92
{
91
- string destinationPath = Path . Combine ( DestinationDirectory , entry . FullName ) ;
92
- string destinationFileName = GetFullDirectoryPathWithSeperator ( destinationPath ) ;
93
- string fullDestDirPath = GetFullDirectoryPathWithSeperator ( DestinationDirectory ) ;
93
+ string destinationPath = Path . GetFullPath ( Path . Combine ( DestinationDirectory , entry . FullName ) ) ;
94
94
95
- CheckDestinationPath ( destinationFileName , fullDestDirPath ) ;
95
+ CheckDestinationPath ( destinationPath , fullDestDirPath ) ;
96
96
97
- if ( ! Directory . Exists ( Path . Combine ( DestinationDirectory , Path . GetDirectoryName ( entry . FullName ) ) ) )
98
- {
99
- Directory . CreateDirectory ( Path . Combine ( DestinationDirectory , Path . GetDirectoryName ( entry . FullName ) ) ) ;
100
- }
97
+ Directory . CreateDirectory ( Path . GetDirectoryName ( destinationPath ) ) ;
101
98
102
99
Log . LogMessage ( Path . GetDirectoryName ( entry . FullName ) ) ;
103
100
entry . ExtractToFile ( destinationPath ) ;
@@ -116,6 +113,7 @@ public override bool Execute()
116
113
using var decompressedStream = new MemoryStream ( ) ;
117
114
decompressor . CopyTo ( decompressedStream ) ;
118
115
decompressedStream . Seek ( 0 , SeekOrigin . Begin ) ;
116
+ string fullDestDirPath = GetFullDirectoryPathWithSeperator ( DestinationDirectory ) ;
119
117
120
118
// Extract Tar content
121
119
using TarReader tr = new TarReader ( decompressedStream ) ;
@@ -127,15 +125,12 @@ public override bool Execute()
127
125
entryName = entryName . StartsWith ( "./" ) ? entryName [ 2 ..] : entryName ;
128
126
if ( ShouldExtractItem ( entryName ) )
129
127
{
130
- string destinationPath = Path . Combine ( DestinationDirectory , entryName ) ;
131
- string destinationFileName = GetFullDirectoryPathWithSeperator ( destinationPath ) ;
132
- string fullDestDirPath = GetFullDirectoryPathWithSeperator ( DestinationDirectory ) ;
128
+ string destinationPath = Path . GetFullPath ( Path . Combine ( DestinationDirectory , entryName ) ) ;
133
129
134
- CheckDestinationPath ( destinationFileName , fullDestDirPath ) ;
130
+ CheckDestinationPath ( destinationPath , fullDestDirPath ) ;
131
+ Directory . CreateDirectory ( Path . GetDirectoryName ( destinationPath ) ) ;
135
132
136
133
Log . LogMessage ( entryName ) ;
137
-
138
- Directory . CreateDirectory ( Path . GetDirectoryName ( destinationPath ) ) ;
139
134
tarEntry . ExtractToFile ( destinationPath , overwrite : true ) ;
140
135
}
141
136
}
@@ -186,7 +181,7 @@ private string GetFullDirectoryPathWithSeperator(string directory)
186
181
{
187
182
string fullDirectoryPath = Path . GetFullPath ( directory ) ;
188
183
189
- if ( ! fullDirectoryPath . EndsWith ( Path . DirectorySeparatorChar . ToString ( ) , StringComparison . OrdinalIgnoreCase ) )
184
+ if ( ! fullDirectoryPath . EndsWith ( Path . DirectorySeparatorChar . ToString ( ) , StringComparison . Ordinal ) )
190
185
{
191
186
fullDirectoryPath = string . Concat ( fullDirectoryPath , Path . DirectorySeparatorChar ) ;
192
187
}
@@ -196,7 +191,7 @@ private string GetFullDirectoryPathWithSeperator(string directory)
196
191
197
192
private void CheckDestinationPath ( string destinationFileName , string fullDestDirPath )
198
193
{
199
- if ( ! destinationFileName . StartsWith ( fullDestDirPath , StringComparison . OrdinalIgnoreCase ) )
194
+ if ( ! destinationFileName . StartsWith ( fullDestDirPath , StringComparison . Ordinal ) )
200
195
{
201
196
throw new System . InvalidOperationException ( "Entry is outside the target dir: " + destinationFileName ) ;
202
197
}
0 commit comments