From 5be63973166b3154e659d046a64e887f7ac5d010 Mon Sep 17 00:00:00 2001 From: Dag Date: Sat, 4 Jan 2025 19:40:53 +0100 Subject: [PATCH] feat: extract simple_html_dom max_file_size to config --- bridges/YoutubeBridge.php | 7 ------- config.default.ini.php | 9 +++++++++ lib/bootstrap.php | 4 ---- lib/simplehtmldom/simple_html_dom.php | 5 +++-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php index 647b1c4202a..12cdaec459e 100644 --- a/bridges/YoutubeBridge.php +++ b/bridges/YoutubeBridge.php @@ -1,12 +1,5 @@ 10 MB) +max_file_size = 10000000 + [http] + ; Operation timeout in seconds timeout = 15 @@ -70,6 +74,7 @@ custom_timeout = false [admin] + ; Advertise an email address where people can reach the administrator. ; This address is displayed on the main page, visible to everyone! ; "" = Disabled (default) @@ -86,6 +91,7 @@ donations = true [proxy] + ; The HTTP proxy to tunnel requests through ; https://curl.se/libcurl/c/CURLOPT_PROXY.html ; "" = Proxy disabled (default) @@ -135,6 +141,7 @@ ; --- Cache specific configuration --------------------------------------------- [FileCache] + ; The root folder to store files in. ; "" = Use the cache folder in the repository (default) path = "" @@ -142,6 +149,7 @@ enable_purge = true [SQLiteCache] + ; Filepath of the sqlite db file file = "cache.sqlite" ; Whether to actually delete data when purging @@ -150,6 +158,7 @@ timeout = 5000 [MemcachedCache] + host = "localhost" port = 11211 diff --git a/lib/bootstrap.php b/lib/bootstrap.php index 36b13e19e30..8a7c62a1a10 100644 --- a/lib/bootstrap.php +++ b/lib/bootstrap.php @@ -7,10 +7,6 @@ const PATH_LIB_CACHES = __DIR__ . '/../caches/'; const PATH_CACHE = __DIR__ . '/../cache/'; -// Allow larger files for simple_html_dom -// todo: extract to config (if possible) -const MAX_FILE_SIZE = 10000000; - // Files $files = [ __DIR__ . '/../lib/html.php', diff --git a/lib/simplehtmldom/simple_html_dom.php b/lib/simplehtmldom/simple_html_dom.php index 170f6fb0960..e8b3a72735f 100644 --- a/lib/simplehtmldom/simple_html_dom.php +++ b/lib/simplehtmldom/simple_html_dom.php @@ -114,8 +114,9 @@ function str_get_html( if (empty($str)) { throw new \Exception('Refusing to parse empty string input'); } - if (strlen($str) > MAX_FILE_SIZE) { - throw new \Exception('Refusing to parse too big input'); + + if (strlen($str) > Configuration::getConfig('system', 'max_file_size')) { + throw new \Exception('simple_html_dom: Refusing to parse too big input: ' . strlen($str)); } return $dom->load($str, $lowercase, $stripRN);