@@ -75,9 +75,7 @@ protected TooManyRedirectsException(SerializationInfo info, StreamingContext con
7575 public override void GetObjectData ( SerializationInfo info , StreamingContext context )
7676 {
7777 if ( info == null )
78- {
79- throw new ArgumentNullException ( "info" ) ;
80- }
78+ throw new ArgumentNullException ( nameof ( info ) ) ;
8179
8280 info . AddValue ( "redirect" , redirect ) ;
8381 info . AddValue ( "uri" , uri , typeof ( Uri ) ) ;
@@ -773,11 +771,29 @@ public static void Put(UpdateProgressDelegate progressDelegate, FuncBool cancell
773771 public static void Get ( DataCopiedDelegate dataCopiedDelegate , FuncBool cancellingDelegate ,
774772 Uri uri , IWebProxy proxy , string path , int timeoutMs )
775773 {
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+
777793 try
778794 {
779795 using ( Stream fileStream = new FileStream ( tmpFile , FileMode . Create , FileAccess . Write , FileShare . None ) ,
780- downloadStream = HttpGetStream ( uri , proxy , timeoutMs ) )
796+ downloadStream = HttpGetStream ( uri , proxy , timeoutMs ) )
781797 {
782798 CopyStream ( downloadStream , fileStream , dataCopiedDelegate , cancellingDelegate ) ;
783799 fileStream . Flush ( ) ;
0 commit comments