diff options
author | Richard Steinmetz <richard@steinmetz.cloud> | 2024-08-27 09:32:04 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2024-08-27 14:01:13 +0000 |
commit | 3de83d8d0bee2ec69165af2596d970946681f800 (patch) | |
tree | 7ff3cf3f772c3a7c513ae78a00bcc5e5fd039757 /lib | |
parent | 5ecccb928a418446c8729e2c9726cb5a3f11386b (diff) | |
download | nextcloud-server-3de83d8d0bee2ec69165af2596d970946681f800.tar.gz nextcloud-server-3de83d8d0bee2ec69165af2596d970946681f800.zip |
fix: gracefully handle unexpected exif orientation types
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/legacy/OC_Image.php | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/private/legacy/OC_Image.php b/lib/private/legacy/OC_Image.php index 74967021405..dfb0d08b1c8 100644 --- a/lib/private/legacy/OC_Image.php +++ b/lib/private/legacy/OC_Image.php @@ -447,6 +447,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. @@ -475,14 +487,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 { @@ -496,10 +505,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; |