@@ -12,31 +12,31 @@ public static void UnzipFileByFile(ZipArchive archive,
1212 {
1313 foreach ( var entry in archive . Entries )
1414 {
15- string fullPath = Path . GetFullPath ( entry . FullName ) ; // $ Alert[cs/zipslip] =r1 $ Alert[cs/zipslip] =r2 $ Alert[cs/zipslip] =r3
15+ string fullPath = Path . GetFullPath ( entry . FullName ) ; // $ Alert=r1 $ Alert=r2 $ Alert=r3
1616 string fileName = Path . GetFileName ( entry . FullName ) ;
1717 string filename = entry . Name ;
18- string file = entry . FullName ; // $ Alert[cs/zipslip] =r4
18+ string file = entry . FullName ; // $ Alert=r4
1919 if ( ! string . IsNullOrEmpty ( file ) )
2020 {
2121 // BAD
2222 string destFileName = Path . Combine ( destDirectory , file ) ;
23- entry . ExtractToFile ( destFileName , true ) ; // $ Sink[cs/zipslip] =r4
23+ entry . ExtractToFile ( destFileName , true ) ; // $ Sink=r4
2424
2525 // GOOD
2626 string sanitizedFileName = Path . Combine ( destDirectory , fileName ) ;
2727 entry . ExtractToFile ( sanitizedFileName , true ) ;
2828
2929 // BAD
3030 string destFilePath = Path . Combine ( destDirectory , fullPath ) ;
31- entry . ExtractToFile ( destFilePath , true ) ; // $ Sink[cs/zipslip] =r1 $ Sink[cs/zipslip] =r2 $ Sink[cs/zipslip] =r3
31+ entry . ExtractToFile ( destFilePath , true ) ; // $ Sink=r1 $ Sink=r2 $ Sink=r3
3232
3333 // BAD: destFilePath isn't fully resolved, so may still contain ..
3434 if ( destFilePath . StartsWith ( destDirectory ) )
35- entry . ExtractToFile ( destFilePath , true ) ; // $ Sink[cs/zipslip] =r2 $ Sink=r1 $ Sink=r3
35+ entry . ExtractToFile ( destFilePath , true ) ; // $ Sink=r2 $ Sink=r1 $ Sink=r3
3636
3737 // BAD
3838 destFilePath = Path . GetFullPath ( Path . Combine ( destDirectory , fullPath ) ) ;
39- entry . ExtractToFile ( destFilePath , true ) ; // $ Sink[cs/zipslip] =r3 $ Sink=r1 $ Sink=r2
39+ entry . ExtractToFile ( destFilePath , true ) ; // $ Sink=r3 $ Sink=r1 $ Sink=r2
4040
4141 // GOOD: a check for StartsWith against a fully resolved path
4242 if ( destFilePath . StartsWith ( destDirectory ) )
@@ -58,36 +58,36 @@ private static int UnzipToStream(Stream zipStream, string installDir)
5858 foreach ( ZipArchiveEntry entry in archive . Entries )
5959 {
6060 // figure out where we are putting the file
61- String destFilePath = Path . Combine ( InstallDir , entry . FullName ) ; // $ Alert[cs/zipslip] =r5 $ Alert[cs/zipslip] =r6 $ Alert[cs/zipslip] =r7 $ Alert[cs/zipslip] =r8
61+ String destFilePath = Path . Combine ( InstallDir , entry . FullName ) ; // $ Alert=r5 $ Alert=r6 $ Alert=r7 $ Alert=r8
6262
6363 Directory . CreateDirectory ( Path . GetDirectoryName ( destFilePath ) ) ;
6464
6565 using ( Stream archiveFileStream = entry . Open ( ) )
6666 {
6767 // BAD: writing to file stream
68- using ( Stream tfsFileStream = new FileStream ( destFilePath , FileMode . CreateNew , FileAccess . ReadWrite , FileShare . None ) ) // $ Sink[cs/zipslip] =r5 $ Sink=r6 $ Sink=r7 $ Sink=r8
68+ using ( Stream tfsFileStream = new FileStream ( destFilePath , FileMode . CreateNew , FileAccess . ReadWrite , FileShare . None ) ) // $ Sink=r5 $ Sink=r6 $ Sink=r7 $ Sink=r8
6969 {
7070 Console . WriteLine ( @"Writing ""{0}""" , destFilePath ) ;
7171 archiveFileStream . CopyTo ( tfsFileStream ) ;
7272 }
7373
7474 // BAD: can do it this way too
75- using ( Stream tfsFileStream = File . Create ( destFilePath ) ) // $ Sink[cs/zipslip] =r6 $ Sink=r5 $ Sink=r7 $ Sink=r8
75+ using ( Stream tfsFileStream = File . Create ( destFilePath ) ) // $ Sink=r6 $ Sink=r5 $ Sink=r7 $ Sink=r8
7676 {
7777 Console . WriteLine ( @"Writing ""{0}""" , destFilePath ) ;
7878 archiveFileStream . CopyTo ( tfsFileStream ) ;
7979 }
8080
8181 // BAD: creating stream using fileInfo
82- var fileInfo = new FileInfo ( destFilePath ) ; // $ Sink[cs/zipslip] =r7 $ Sink=r5 $ Sink=r6 $ Sink=r8
82+ var fileInfo = new FileInfo ( destFilePath ) ; // $ Sink=r7 $ Sink=r5 $ Sink=r6 $ Sink=r8
8383 using ( FileStream fs = fileInfo . OpenWrite ( ) )
8484 {
8585 Console . WriteLine ( @"Writing ""{0}""" , destFilePath ) ;
8686 archiveFileStream . CopyTo ( fs ) ;
8787 }
8888
8989 // BAD: creating stream using fileInfo
90- var fileInfo1 = new FileInfo ( destFilePath ) ; // $ Sink[cs/zipslip] =r8 $ Sink=r5 $ Sink=r6 $ Sink=r7
90+ var fileInfo1 = new FileInfo ( destFilePath ) ; // $ Sink=r8 $ Sink=r5 $ Sink=r6 $ Sink=r7
9191 using ( FileStream fs = fileInfo1 . Open ( FileMode . Create ) )
9292 {
9393 Console . WriteLine ( @"Writing ""{0}""" , destFilePath ) ;
0 commit comments