From 0525597a15af0b7db939b637a14c85401a1620c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B8nstantine=20Kovalensky?= <45331093+kovalensky@users.noreply.github.com> Date: Wed, 20 Dec 2023 22:47:32 +0400 Subject: [PATCH] Handle & show upload_max_filesize occurences (#1241) --- library/ajax/view_torrent.php | 2 +- library/includes/file_list_v2.php | 2 +- src/Legacy/Attach.php | 17 +++++++++++++++-- src/Legacy/Torrent.php | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/library/ajax/view_torrent.php b/library/ajax/view_torrent.php index 29c32b18f..e40364626 100644 --- a/library/ajax/view_torrent.php +++ b/library/ajax/view_torrent.php @@ -30,7 +30,7 @@ if (!file_exists($filename) || !$file_contents = file_get_contents($filename)) { try { $tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY); -} catch (Exception) { +} catch (\Exception) { $this->response['html'] = $lang['TORFILE_INVALID']; return; } diff --git a/library/includes/file_list_v2.php b/library/includes/file_list_v2.php index 79fa835b2..f1f770ff5 100644 --- a/library/includes/file_list_v2.php +++ b/library/includes/file_list_v2.php @@ -62,7 +62,7 @@ if ($bb_cfg['flist_max_files']) { try { $torrent = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY); -} catch (Exception) { +} catch (\Exception) { http_response_code(410); die($lang['TORFILE_INVALID']); } diff --git a/src/Legacy/Attach.php b/src/Legacy/Attach.php index 92a45a7a9..0b0782d1b 100644 --- a/src/Legacy/Attach.php +++ b/src/Legacy/Attach.php @@ -734,9 +734,22 @@ class Attach $file = $_FILES['fileupload']['tmp_name']; $this->type = $_FILES['fileupload']['type']; - if (isset($_FILES['fileupload']['size']) && $_FILES['fileupload']['size'] == 0) { - bb_die('Tried to upload empty file'); + if (isset($_FILES['fileupload']['error'])) { + switch($_FILES['fileupload']['error']) { + case UPLOAD_ERR_NO_FILE: + bb_die('No file content sent'); + case UPLOAD_ERR_INI_SIZE: + bb_die('upload_max_filesize setting: ' . ini_get('upload_max_filesize')); + case UPLOAD_ERR_CANT_WRITE: + bb_die('Failed to write file to disk, check permissions'); + case UPLOAD_ERR_PARTIAL: + bb_die('The uploaded file was only partially uploaded'); } + } + + if (isset($_FILES['fileupload']['size']) && $_FILES['fileupload']['size'] === 0) { + bb_die('Tried to upload empty file'); + } $this->type = strtolower($this->type); $this->extension = strtolower(get_extension($this->filename)); diff --git a/src/Legacy/Torrent.php b/src/Legacy/Torrent.php index 309ced7bf..39a1defaf 100644 --- a/src/Legacy/Torrent.php +++ b/src/Legacy/Torrent.php @@ -319,7 +319,7 @@ class Torrent try { $tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY); - } catch (Exception) { + } catch (\Exception $e) { self::torrent_error_exit($lang['TORFILE_INVALID']); } @@ -563,7 +563,7 @@ class Torrent $file_contents = file_get_contents($filename); try { $tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY); - } catch (Exception) { + } catch (\Exception) { bb_die($lang['TORFILE_INVALID']); }