Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] fix: gracefully handle unexpected exif orientation types #47531

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions lib/private/legacy/OC_Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,18 @@ protected function getWebpQuality(): int {
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.
Expand Down Expand Up @@ -475,14 +487,11 @@ public function getOrientation(): int {
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 {
Expand All @@ -496,10 +505,7 @@ public function readExif($data): void {
}

$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;
Expand Down
Loading