From 91a5a73dca110aad9f44a90ebfc089517ae351b6 Mon Sep 17 00:00:00 2001 From: 3D-I <480857+3D-I@users.noreply.github.com> Date: Tue, 9 Feb 2021 23:43:15 +0100 Subject: [PATCH 1/4] [ticket/16705] Fix check_disk_space function PHPBB3-16705 --- phpBB/language/en/posting.php | 1 + phpBB/phpbb/attachment/upload.php | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/phpBB/language/en/posting.php b/phpBB/language/en/posting.php index 1a6866d535..4d2ce46252 100644 --- a/phpBB/language/en/posting.php +++ b/phpBB/language/en/posting.php @@ -46,6 +46,7 @@ $lang = array_merge($lang, array( 'ATTACH_COMMENT_NO_EMOJIS' => 'The attachment comment contains forbidden characters (Emoji).', 'ATTACH_DISK_FULL' => 'There is not enough free disk space to post this attachment.', 'ATTACH_QUOTA_REACHED' => 'Sorry, the board attachment quota has been reached.', + 'ATTACH_DISK_FREE_SPACE' => 'Sorry, the PHP disk_free_space function is disabled in this system.', 'ATTACH_SIG' => 'Attach a signature (signatures can be altered via the UCP)', 'BBCODE_A_HELP' => 'Inline uploaded attachment: [attachment=]filename.ext[/attachment]', diff --git a/phpBB/phpbb/attachment/upload.php b/phpBB/phpbb/attachment/upload.php index ca83f9dabf..52f60348a9 100644 --- a/phpBB/phpbb/attachment/upload.php +++ b/phpBB/phpbb/attachment/upload.php @@ -296,8 +296,10 @@ class upload */ protected function check_disk_space() { - if ($free_space = @disk_free_space($this->phpbb_root_path . $this->config['upload_path'])) + if (function_exists('disk_free_space')) { + $free_space = disk_free_space($this->phpbb_root_path); + if ($free_space <= $this->file->get('filesize')) { if ($this->auth->acl_get('a_')) @@ -315,6 +317,16 @@ class upload return false; } } + else + { + $this->file_data['error'][] = $this->language->lang('ATTACH_DISK_FREE_SPACE'); + + $this->file_data['post_attach'] = false; + + $this->file->remove(); + + return false; + } return true; } From e4fc9bb0b1857f132a2754e24791861ad01a8530 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 2 Mar 2021 19:55:02 +0100 Subject: [PATCH 2/4] [ticket/16705] Correctly assign phpBB root path in tests PHPBB3-16705 --- tests/attachment/upload_test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/attachment/upload_test.php b/tests/attachment/upload_test.php index 2743ee596d..0f4204dfff 100644 --- a/tests/attachment/upload_test.php +++ b/tests/attachment/upload_test.php @@ -79,6 +79,7 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case 'img_create_thumbnail' => true, )); $config = $this->config; + $this->phpbb_root_path = $phpbb_root_path; $this->db = $this->new_dbal(); $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\dummy(), $this->config, $this->db, $phpbb_root_path, $phpEx); $this->request = $this->createMock('\phpbb\request\request'); From 2ea22ee387d8c4cec050ef19eaa8a8cf70e56add Mon Sep 17 00:00:00 2001 From: 3D-I Date: Fri, 5 Mar 2021 08:00:55 +0100 Subject: [PATCH 3/4] [ticket/16705] Fix check_disk_space function Silent potential warnings PHPBB3-16705 --- phpBB/phpbb/attachment/upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/attachment/upload.php b/phpBB/phpbb/attachment/upload.php index 52f60348a9..9f18f2429f 100644 --- a/phpBB/phpbb/attachment/upload.php +++ b/phpBB/phpbb/attachment/upload.php @@ -298,7 +298,7 @@ class upload { if (function_exists('disk_free_space')) { - $free_space = disk_free_space($this->phpbb_root_path); + $free_space = @disk_free_space($this->phpbb_root_path); if ($free_space <= $this->file->get('filesize')) { From 5d18ad678b05a05520b1b4c2e0d86d128ff5b053 Mon Sep 17 00:00:00 2001 From: 3D-I Date: Fri, 5 Mar 2021 08:02:53 +0100 Subject: [PATCH 4/4] [ticket/16705] Fix check_disk_space function Allow upload even if the check fails PHPBB3-16705 --- phpBB/language/en/posting.php | 1 - phpBB/phpbb/attachment/upload.php | 10 ---------- 2 files changed, 11 deletions(-) diff --git a/phpBB/language/en/posting.php b/phpBB/language/en/posting.php index 4d2ce46252..1a6866d535 100644 --- a/phpBB/language/en/posting.php +++ b/phpBB/language/en/posting.php @@ -46,7 +46,6 @@ $lang = array_merge($lang, array( 'ATTACH_COMMENT_NO_EMOJIS' => 'The attachment comment contains forbidden characters (Emoji).', 'ATTACH_DISK_FULL' => 'There is not enough free disk space to post this attachment.', 'ATTACH_QUOTA_REACHED' => 'Sorry, the board attachment quota has been reached.', - 'ATTACH_DISK_FREE_SPACE' => 'Sorry, the PHP disk_free_space function is disabled in this system.', 'ATTACH_SIG' => 'Attach a signature (signatures can be altered via the UCP)', 'BBCODE_A_HELP' => 'Inline uploaded attachment: [attachment=]filename.ext[/attachment]', diff --git a/phpBB/phpbb/attachment/upload.php b/phpBB/phpbb/attachment/upload.php index 9f18f2429f..7cd94d0858 100644 --- a/phpBB/phpbb/attachment/upload.php +++ b/phpBB/phpbb/attachment/upload.php @@ -317,16 +317,6 @@ class upload return false; } } - else - { - $this->file_data['error'][] = $this->language->lang('ATTACH_DISK_FREE_SPACE'); - - $this->file_data['post_attach'] = false; - - $this->file->remove(); - - return false; - } return true; }