From 309dbb4ef9d6b2c29aa6294002ce1a7d4da2b099 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 24 Jun 2014 19:07:49 +0200 Subject: [PATCH] [ticket/12755] Terminate upload loop if upload reaches filesize Terminate the upload loop if the expected filesize has been reached instead of trying to read more bytes until the timeout has been reached. PHPBB3-12755 --- phpBB/includes/functions_upload.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_upload.php b/phpBB/includes/functions_upload.php index c6e2dddf3d..daa3550205 100644 --- a/phpBB/includes/functions_upload.php +++ b/phpBB/includes/functions_upload.php @@ -803,13 +803,23 @@ class fileupload $get_info = false; $data = ''; + $length = false; $timer_stop = time() + $this->upload_timeout; - while (!@feof($fsock)) + 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)