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

ExifProvider.php: handle unhandled exception #35932

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 6 additions & 1 deletion lib/private/Metadata/Provider/ExifProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ public function execute(File $file): array {
$size->setMetadata([]);

if (!$data) {
$sizeResult = getimagesizefromstring($file->getContent());
try {
$sizeResult = getimagesizefromstring($file->getContent());
} catch (\Throwable $ex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work:

php > try {getimagesize('foobar');} catch(\Throwable $e){}
PHP Warning:  getimagesize(foobar): Failed to open stream: No such file or directory in php shell code on line 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably same reason as in #36420 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would work from scan command because scan command converts warning into Exception, but that’s really ugly. It should be handled in Scan command as it is the one doing the conversion.

$this->logger->warning("Couldn't get image for ".$file->getId(), ['exception' => $ex]);
Comment on lines +72 to +74
Copy link
Contributor

@szaimen szaimen Apr 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in https://github.com/nextcloud/server/pull/36420/files

Suggested change
$sizeResult = getimagesizefromstring($file->getContent());
} catch (\Throwable $ex) {
$this->logger->warning("Couldn't get image for ".$file->getId(), ['exception' => $ex]);
$sizeResult = @getimagesizefromstring($file->getContent());
} catch (\Exception $ex) {
$this->logger->info("Couldn't get image for ".$file->getId(), ['exception' => $ex]);

$sizeResult = false;
}
if ($sizeResult !== false) {
$size->setMetadata([
'width' => $sizeResult[0],
Expand Down