From 91c137b26434bb5094113f014193ba9bc43615c4 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Mon, 30 Nov 2020 17:25:48 -0800 Subject: [PATCH] Fix missing error message when embedding fails --- imgboard.php | 7 ++++++- inc/functions.php | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/imgboard.php b/imgboard.php index db77203..2169965 100644 --- a/imgboard.php +++ b/imgboard.php @@ -338,8 +338,9 @@ if (!isset($_GET['delete']) && !isset($_GET['manage']) && (isset($_POST['name']) if (!TINYIB_UPLOADVIAURL) { fancyDie(sprintf(__('Invalid embed URL. Only %s URLs are supported.'), implode('/', array_keys($tinyib_embeds)))); } + $headers = get_headers(trim($_POST['embed']), true); - if (TINYIB_MAXKB > 0 && intval($headers['Content-Length']) > (TINYIB_MAXKB * 1024)) { + if (TINYIB_MAXKB > 0 && isset($headers['Content-Length']) && intval($headers['Content-Length']) > (TINYIB_MAXKB * 1024)) { fancyDie(sprintf(__('That file is larger than %s.'), TINYIB_MAXKBDESC)); } @@ -348,6 +349,10 @@ if (!isset($_GET['delete']) && !isset($_GET['manage']) && (isset($_POST['name']) fancyDie(__('Failed to download file at specified URL.')); } + if (TINYIB_MAXKB > 0 && strlen($data) > (TINYIB_MAXKB * 1024)) { + fancyDie(sprintf(__('That file is larger than %s.'), TINYIB_MAXKBDESC)); + } + $filepath = 'src/' . time() . substr(microtime(), 2, 3) . rand(1000, 9999) . '.txt'; if (!file_put_contents($filepath, $data)) { @unlink($filepath); diff --git a/inc/functions.php b/inc/functions.php index 41b476a..42c50aa 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -574,9 +574,15 @@ function url_get_contents($url) { curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $output = curl_exec($ch); + $responsecode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + if (intval($responsecode) != 200) { + return ''; + } return $output; } @@ -589,9 +595,12 @@ function getEmbed($url) { global $tinyib_embeds; foreach ($tinyib_embeds as $service => $service_url) { $service_url = str_ireplace("TINYIBEMBED", urlencode($url), $service_url); - $result = json_decode(url_get_contents($service_url), true); - if (!empty($result)) { - return array($service, $result); + $data = url_get_contents($service_url); + if ($data != '') { + $result = json_decode($data, true); + if (!empty($result)) { + return array($service, $result); + } } }