]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: gracefully handle unexpected exif orientation types 47533/head
authorRichard Steinmetz <richard@steinmetz.cloud>
Tue, 27 Aug 2024 07:32:04 +0000 (09:32 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Tue, 27 Aug 2024 14:05:00 +0000 (14:05 +0000)
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
lib/private/legacy/OC_Image.php

index 1d2326dcce95c853fa9a11ce26fe2137bc25cae6..827ea16039bd31378606a430225d26cb59946343 100644 (file)
@@ -390,6 +390,18 @@ class OC_Image implements \OCP\IImage {
                return min(100, max(10, (int) $quality));
        }
 
+       private function isValidExifData(array $exif): bool {
+               if (!isset($exif['Orientation'])) {
+                       return false;
+               }
+
+               if (!is_numeric($exif['Orientation'])) {
+                       return false;
+               }
+
+               return true;
+       }
+
        /**
         * (I'm open for suggestions on better method name ;)
         * Get the orientation based on EXIF data.
@@ -418,14 +430,11 @@ class OC_Image implements \OCP\IImage {
                        return -1;
                }
                $exif = @exif_read_data($this->filePath, 'IFD0');
-               if (!$exif) {
-                       return -1;
-               }
-               if (!isset($exif['Orientation'])) {
+               if (!$exif || !$this->isValidExifData($exif)) {
                        return -1;
                }
                $this->exif = $exif;
-               return $exif['Orientation'];
+               return (int)$exif['Orientation'];
        }
 
        public function readExif($data): void {
@@ -439,10 +448,7 @@ class OC_Image implements \OCP\IImage {
                }
 
                $exif = @exif_read_data('data://image/jpeg;base64,' . base64_encode($data));
-               if (!$exif) {
-                       return;
-               }
-               if (!isset($exif['Orientation'])) {
+               if (!$exif || !$this->isValidExifData($exif)) {
                        return;
                }
                $this->exif = $exif;