aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2014-06-24 20:59:11 +0200
committerAndreas Fischer <bantu@phpbb.com>2014-06-24 20:59:11 +0200
commitb5b0175d59ce32e5bd16d71d3ab1aec8435388ea (patch)
tree768b5cb3ae9ad6a69e76aac7d87492fecb8fc70b /phpBB/includes
parent1edcfcb5020f8199860295020e5e33d030ab772b (diff)
parent2596dbc850df86dd0d620e9d90bfd59a2f23a0eb (diff)
downloadforums-b5b0175d59ce32e5bd16d71d3ab1aec8435388ea.tar
forums-b5b0175d59ce32e5bd16d71d3ab1aec8435388ea.tar.gz
forums-b5b0175d59ce32e5bd16d71d3ab1aec8435388ea.tar.bz2
forums-b5b0175d59ce32e5bd16d71d3ab1aec8435388ea.tar.xz
forums-b5b0175d59ce32e5bd16d71d3ab1aec8435388ea.zip
Merge branch 'develop-olympus' into develop-ascraeus
* develop-olympus: [ticket/12755] Apply de morgan to conditional [ticket/12755] Terminate upload loop if upload reaches filesize [ticket/12755] Change upload in remote_upload() method to fit get_remote_file [ticket/12755] Add language string for timed out remote upload [ticket/12755] Add timeout to remote upload to prevent infinite loop
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/functions_upload.php31
1 files changed, 29 insertions, 2 deletions
diff --git a/phpBB/includes/functions_upload.php b/phpBB/includes/functions_upload.php
index c640865212..0847c3a550 100644
--- a/phpBB/includes/functions_upload.php
+++ b/phpBB/includes/functions_upload.php
@@ -485,6 +485,9 @@ class fileupload
var $max_height = 0;
var $error_prefix = '';
+ /** @var int Timeout for remote upload */
+ var $upload_timeout = 6;
+
/**
* Init file upload class.
*
@@ -828,13 +831,28 @@ class fileupload
fputs($fsock, "HOST: " . $host . "\r\n");
fputs($fsock, "Connection: close\r\n\r\n");
+ // Set a proper timeout for the socket
+ socket_set_timeout($fsock, $this->upload_timeout);
+
$get_info = false;
$data = '';
- while (!@feof($fsock))
+ $length = false;
+ $timer_stop = time() + $this->upload_timeout;
+
+ while ((!$length || $filesize < $length) && !@feof($fsock))
{
if ($get_info)
{
- $block = @fread($fsock, 1024);
+ if ($length)
+ {
+ // Don't attempt to read past end of file if server indicated length
+ $block = @fread($fsock, min($length - $filesize, 1024));
+ }
+ else
+ {
+ $block = @fread($fsock, 1024);
+ }
+
$filesize += strlen($block);
if ($remote_max_filesize && $filesize > $remote_max_filesize)
@@ -880,6 +898,15 @@ class fileupload
}
}
}
+
+ $stream_meta_data = stream_get_meta_data($fsock);
+
+ // Cancel upload if we exceed timeout
+ if (!empty($stream_meta_data['timed_out']) || time() >= $timer_stop)
+ {
+ $file = new fileerror($user->lang[$this->error_prefix . 'REMOTE_UPLOAD_TIMEOUT']);
+ return $file;
+ }
}
@fclose($fsock);