]> git.mxchange.org Git - friendica.git/commitdiff
Cleanup
authorPhilipp <admin@philipp.info>
Fri, 20 Aug 2021 18:03:42 +0000 (20:03 +0200)
committerPhilipp <admin@philipp.info>
Fri, 20 Aug 2021 18:03:42 +0000 (20:03 +0200)
src/Content/Text/BBCode.php
src/Model/Photo.php
src/Model/User.php
src/Network/Probe.php
src/Util/Images.php

index ce6b360817db3c0e9d80faf2d7c9d34b0207074c..cd433bdbb8e66191809a5dceb074112e06c651c2 100644 (file)
@@ -499,8 +499,8 @@ class BBCode
                                }
 
                                $i = $curlResult->getBody();
-                               $contType = $curlResult->getContentType();
-                               $type = Images::getMimeTypeByData($i, $mtch[1], $contType);
+                               $type = $curlResult->getContentType();
+                               $type = Images::getMimeTypeByData($i, $mtch[1], $type);
 
                                if ($i) {
                                        $Image = new Image($i, $type);
index 2a2d02f86f66ec6c7824b03becc1c65646ae8423..23e0b9a38c660e67e80649aec41fadd7011a27c4 100644 (file)
@@ -492,17 +492,17 @@ class Photo
                if (!empty($image_url)) {
                        $ret = DI::httpRequest()->get($image_url);
                        $img_str = $ret->getBody();
-                       $contType = $ret->getContentType();
+                       $type = $ret->getContentType();
                } else {
                        $img_str = '';
-                       $contType = '';
+                       $type = '';
                }
 
                if ($quit_on_error && ($img_str == "")) {
                        return false;
                }
 
-               $type = Images::getMimeTypeByData($img_str, $image_url, $contType);
+               $type = Images::getMimeTypeByData($img_str, $image_url, $type);
 
                $Image = new Image($img_str, $type);
                if ($Image->isValid()) {
index 34a7b78a49fc2a578c49ef9fee4ad43b76722096..49423ce9ef74792b17423aabd52380ef7ec5006e 100644 (file)
@@ -1095,13 +1095,13 @@ class User
                        $curlResult = DI::httpRequest()->get($photo);
                        if ($curlResult->isSuccess()) {
                                $img_str = $curlResult->getBody();
-                               $contType = $curlResult->getContentType();
+                               $type = $curlResult->getContentType();
                        } else {
                                $img_str = '';
-                               $contType = '';
+                               $type = '';
                        }
 
-                       $type = Images::getMimeTypeByData($img_str, $photo, $contType);
+                       $type = Images::getMimeTypeByData($img_str, $photo, $type);
 
                        $Image = new Image($img_str, $type);
                        if ($Image->isValid()) {
index 1115808007a99c420a8f4fadb01fd1924a868a30..c547afcd4d0655ded20d6a121839458db3cd3786 100644 (file)
@@ -429,6 +429,11 @@ class Probe
                        return false;
                }
 
+               // If the file is too large then exit
+               if (($curlResult->getInfo()['download_content_length'] ?? 0) > 1000000) {
+                       return false;
+               }
+
                // If it isn't a HTML file then exit
                if (($curlResult->getContentType() != '') && !strstr(strtolower($curlResult->getContentType()), 'html')) {
                        return false;
index 1dcca2e3929a13e140df56c8829fc4d6d88758a5..bf84ee6c22552bad74d3db1eb83272a5bc52f0d3 100644 (file)
@@ -77,21 +77,21 @@ class Images
         *
         * @param string $image_data Image data
         * @param string $filename   File name (for guessing the type via the extension)
-        * @param string $mimeType   possible mime type
+        * @param string $mime       default mime type
         *
         * @return string
         * @throws \Exception
         */
-       public static function getMimeTypeByData(string $image_data, string $filename = '', string $mimeType = '')
+       public static function getMimeTypeByData(string $image_data, string $filename = '', string $mime = '')
        {
-               if (substr($mimeType, 0, 6) == 'image/') {
-                       Logger::info('Using default mime type', ['filename' => $filename, 'mime' => $mimeType]);
-                       return $mimeType;
+               if (substr($mime, 0, 6) == 'image/') {
+                       Logger::info('Using default mime type', ['filename' => $filename, 'mime' => $mime]);
+                       return $mime;
                }
 
                $image = @getimagesizefromstring($image_data);
                if (!empty($image['mime'])) {
-                       Logger::info('Mime type detected via data', ['filename' => $filename, 'default' => $mimeType, 'mime' => $image['mime']]);
+                       Logger::info('Mime type detected via data', ['filename' => $filename, 'default' => $mime, 'mime' => $image['mime']]);
                        return $image['mime'];
                }