@@ -430,8 +430,10 @@ public function fastDownload($url, $filename, $connections = 4)
430430
431431 $ curl ->downloadCompleteCallback = function ($ instance , $ tmpfile ) use ($ part_file_name ) {
432432 $ fh = fopen ($ part_file_name , 'wb ' );
433- stream_copy_to_stream ($ tmpfile , $ fh );
434- fclose ($ fh );
433+ if ($ fh !== false ) {
434+ stream_copy_to_stream ($ tmpfile , $ fh );
435+ fclose ($ fh );
436+ }
435437 };
436438
437439 $ multi_curl ->addCurl ($ curl );
@@ -447,6 +449,9 @@ public function fastDownload($url, $filename, $connections = 4)
447449
448450 // Combine downloaded chunks into a single file.
449451 $ main_file_handle = fopen ($ filename , 'w ' );
452+ if ($ main_file_handle === false ) {
453+ return false ;
454+ }
450455
451456 foreach ($ part_file_names as $ part_file_name ) {
452457 if (!is_file ($ part_file_name )) {
@@ -1031,7 +1036,7 @@ public function setHeaders($headers)
10311036 }
10321037 } else {
10331038 foreach ($ headers as $ header ) {
1034- list ($ key , $ value ) = explode (': ' , $ header , 2 );
1039+ list ($ key , $ value ) = array_pad ( explode (': ' , $ header , 2 ), 2 , '' );
10351040 $ key = trim ($ key );
10361041 $ value = trim ($ value );
10371042 $ this ->headers [$ key ] = $ value ;
@@ -1404,7 +1409,7 @@ public function diagnose($return = false)
14041409 if (isset ($ this ->responseHeaders ['Content-Length ' ])) {
14051410 echo 'Response content length (from content-length header): ' . $ response_header_length . "\n" ;
14061411 } else {
1407- echo 'Response content length (calculated): ' . $ response_calculated_length . "\n" ;
1412+ echo 'Response content length (calculated): ' . ( string ) $ response_calculated_length . "\n" ;
14081413 }
14091414
14101415 if (
@@ -1859,13 +1864,15 @@ private function downloadComplete($fh)
18591864 // Fix "PHP Notice: Use of undefined constant STDOUT" when reading the
18601865 // PHP script from stdin. Using null causes "Warning: curl_setopt():
18611866 // supplied argument is not a valid File-Handle resource".
1862- if (!defined ('STDOUT ' )) {
1863- define ('STDOUT ' , fopen ('php://stdout ' , 'w ' ));
1867+ if (defined ('STDOUT ' )) {
1868+ $ output = STDOUT ;
1869+ } else {
1870+ $ output = fopen ('php://stdout ' , 'w ' );
18641871 }
18651872
18661873 // Reset CURLOPT_FILE with STDOUT to avoid: "curl_exec(): CURLOPT_FILE
18671874 // resource has gone away, resetting to default".
1868- $ this ->setFile (STDOUT );
1875+ $ this ->setFile ($ output );
18691876
18701877 // Reset CURLOPT_RETURNTRANSFER to tell cURL to return subsequent
18711878 // responses as the return value of curl_exec(). Without this,
@@ -1881,13 +1888,16 @@ private function downloadComplete($fh)
18811888 */
18821889 private function parseHeaders ($ raw_headers )
18831890 {
1884- $ raw_headers = preg_split ('/\r\n/ ' , (string ) $ raw_headers , -1 , PREG_SPLIT_NO_EMPTY );
18851891 $ http_headers = new CaseInsensitiveArray ();
1892+ $ raw_headers = preg_split ('/\r\n/ ' , (string ) $ raw_headers , -1 , PREG_SPLIT_NO_EMPTY );
1893+ if ($ raw_headers === false ) {
1894+ return ['' , $ http_headers ];
1895+ }
18861896
18871897 $ raw_headers_count = count ($ raw_headers );
18881898 for ($ i = 1 ; $ i < $ raw_headers_count ; $ i ++) {
18891899 if (strpos ($ raw_headers [$ i ], ': ' ) !== false ) {
1890- list ($ key , $ value ) = explode (': ' , $ raw_headers [$ i ], 2 );
1900+ list ($ key , $ value ) = array_pad ( explode (': ' , $ raw_headers [$ i ], 2 ), 2 , '' );
18911901 $ key = trim ($ key );
18921902 $ value = trim ($ value );
18931903 // Use isset() as array_key_exists() and ArrayAccess are not compatible.
0 commit comments