Merge pull request #47509 from nextcloud/fix/exif-orientation-type

fix: gracefully handle unexpected exif orientation types
This commit is contained in:
Daniel 2024-08-27 15:59:14 +02:00 committed by GitHub
commit 11822def85
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View 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;