diff options
author | Richard Steinmetz <richard@steinmetz.cloud> | 2024-08-27 09:32:04 +0200 |
---|---|---|
committer | Richard Steinmetz <richard@steinmetz.cloud> | 2024-08-27 09:32:04 +0200 |
commit | cd928ed4ed6dae4b4a55cea39cd910883188091d (patch) | |
tree | 2be0061fd4c13d4331ce1e42c0f5daa184434349 /lib/private/legacy | |
parent | b8ab7b7e556d7bc71597a2ca716652b80174719d (diff) | |
download | nextcloud-server-cd928ed4ed6dae4b4a55cea39cd910883188091d.tar.gz nextcloud-server-cd928ed4ed6dae4b4a55cea39cd910883188091d.zip |
fix: gracefully handle unexpected exif orientation types
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Diffstat (limited to 'lib/private/legacy')
-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 56fe96cda60..37cf6b697ac 100644 --- a/lib/private/legacy/OC_Image.php +++ b/lib/private/legacy/OC_Image.php @@ -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; |