@@ -75,9 +75,7 @@ protected TooManyRedirectsException(SerializationInfo info, StreamingContext con
75
75
public override void GetObjectData ( SerializationInfo info , StreamingContext context )
76
76
{
77
77
if ( info == null )
78
- {
79
- throw new ArgumentNullException ( "info" ) ;
80
- }
78
+ throw new ArgumentNullException ( nameof ( info ) ) ;
81
79
82
80
info . AddValue ( "redirect" , redirect ) ;
83
81
info . AddValue ( "uri" , uri , typeof ( Uri ) ) ;
@@ -773,11 +771,29 @@ public static void Put(UpdateProgressDelegate progressDelegate, FuncBool cancell
773
771
public static void Get ( DataCopiedDelegate dataCopiedDelegate , FuncBool cancellingDelegate ,
774
772
Uri uri , IWebProxy proxy , string path , int timeoutMs )
775
773
{
776
- string tmpFile = Path . GetTempFileName ( ) ;
774
+ if ( string . IsNullOrWhiteSpace ( path ) )
775
+ throw new ArgumentException ( nameof ( path ) ) ;
776
+
777
+ var tmpFile = Path . GetTempFileName ( ) ;
778
+
779
+ if ( Path . GetPathRoot ( path ) != Path . GetPathRoot ( tmpFile ) )
780
+ {
781
+ //CA-365905: if the target path is under a root different from
782
+ //the temp file, use instead a temp file under the target root,
783
+ //otherwise there may not be enough space for the download
784
+
785
+ var dir = Path . GetDirectoryName ( path ) ;
786
+ if ( dir == null ) //path is root directory
787
+ throw new ArgumentException ( nameof ( path ) ) ;
788
+
789
+ tmpFile = Path . Combine ( dir , Path . GetRandomFileName ( ) ) ;
790
+ File . Delete ( tmpFile ) ;
791
+ }
792
+
777
793
try
778
794
{
779
795
using ( Stream fileStream = new FileStream ( tmpFile , FileMode . Create , FileAccess . Write , FileShare . None ) ,
780
- downloadStream = HttpGetStream ( uri , proxy , timeoutMs ) )
796
+ downloadStream = HttpGetStream ( uri , proxy , timeoutMs ) )
781
797
{
782
798
CopyStream ( downloadStream , fileStream , dataCopiedDelegate , cancellingDelegate ) ;
783
799
fileStream . Flush ( ) ;
0 commit comments