aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRichard Steinmetz <richard@steinmetz.cloud>2024-08-27 19:28:22 +0200
committerGitHub <noreply@github.com>2024-08-27 19:28:22 +0200
commit6c73b1159156d0a22a44edb215fe1eebaf7307c2 (patch)
treeb3527ecd6617a1a29c3b30e889508ec9b7275921 /lib/private
parent01b5d36515f95fdd095ae0bc8ae37332e8ea372f (diff)
parent3f1eefd85bcba8ba4c5abcbb691963b1625f61ae (diff)
downloadnextcloud-server-6c73b1159156d0a22a44edb215fe1eebaf7307c2.tar.gz
nextcloud-server-6c73b1159156d0a22a44edb215fe1eebaf7307c2.zip
Merge pull request #47536 from nextcloud/backport/47509/stable29
[stable29] fix: gracefully handle unexpected exif orientation types
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/legacy/OC_Image.php24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/private/legacy/OC_Image.php b/lib/private/legacy/OC_Image.php
index 56b75c999cb..a79c05e56ec 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;