File tree Expand file tree Collapse file tree 1 file changed +9
-17
lines changed
src/Application/src/RazorPagesTestSample/Pages Expand file tree Collapse file tree 1 file changed +9
-17
lines changed Original file line number Diff line number Diff line change @@ -94,22 +94,14 @@ public async Task<IActionResult> OnPostAnalyzeMessagesAsync()
94
94
95
95
96
96
97
- public static void WriteToDirectory ( ZipArchiveEntry entry , string destDirectory )
98
- {
99
- // Get the full path of the destination file
100
- string destFileName = Path . Combine ( destDirectory , entry . FullName ) ;
101
-
102
- // Ensure the destination directory exists
103
- Directory . CreateDirectory ( Path . GetDirectoryName ( destFileName ) ) ;
104
-
105
- // Check if the destination file path is within the intended directory
106
- if ( ! destFileName . StartsWith ( Path . GetFullPath ( destDirectory ) , StringComparison . OrdinalIgnoreCase ) )
107
- {
108
- throw new InvalidOperationException ( "Attempt to extract file outside of the destination directory." ) ;
109
- }
110
-
111
- // Extract the file
112
- entry . ExtractToFile ( destFileName , overwrite : true ) ;
113
- }
97
+ public static void WriteToDirectory ( ZipArchiveEntry entry , string destDirectory )
98
+ {
99
+ string destFileName = Path . GetFullPath ( Path . Combine ( destDirectory , entry . FullName ) ) ;
100
+ string fullDestDirPath = Path . GetFullPath ( destDirectory + Path . DirectorySeparatorChar ) ;
101
+ if ( ! destFileName . StartsWith ( fullDestDirPath ) ) {
102
+ throw new System . InvalidOperationException ( "Entry is outside the target dir: " + destFileName ) ;
103
+ }
104
+ entry . ExtractToFile ( destFileName ) ;
105
+ }
114
106
}
115
107
}
You can’t perform that action at this time.
0 commit comments