From: Lukas Reschke Date: Thu, 8 Jan 2015 17:33:35 +0000 (+0100) Subject: Verify whether type is correct X-Git-Tag: v8.0.0alpha2~24^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ceaaab6295ad30e066c9d5505e9131136bafbdb8;p=nextcloud-server.git Verify whether type is correct `$this->info` can very well contain an empty array or possibly other values. This means that when this code path is called a PHP Fatal error might get thrown which is not what we want. --- diff --git a/core/ajax/preview.php b/core/ajax/preview.php index 03dfb483062..f7e24e0ec28 100644 --- a/core/ajax/preview.php +++ b/core/ajax/preview.php @@ -29,21 +29,17 @@ if ($maxX === 0 || $maxY === 0) { exit; } -try { - $preview = new \OC\Preview(\OC_User::getUser(), 'files'); - $info = \OC\Files\Filesystem::getFileInfo($file); - if (!$always and !$preview->isAvailable($info)) { - \OC_Response::setStatus(404); - } else { - $preview->setFile($file); - $preview->setMaxX($maxX); - $preview->setMaxY($maxY); - $preview->setScalingUp($scalingUp); - $preview->setKeepAspect($keepAspect); - $preview->showPreview(); - } +$preview = new \OC\Preview(\OC_User::getUser(), 'files'); -} catch (\Exception $e) { - \OC_Response::setStatus(500); - \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG); +$info = \OC\Files\Filesystem::getFileInfo($file); + +if (!$info instanceof OCP\Files\FileInfo || !$always && !$preview->isAvailable($info)) { + \OC_Response::setStatus(404); +} else { + $preview->setFile($file); + $preview->setMaxX($maxX); + $preview->setMaxY($maxY); + $preview->setScalingUp($scalingUp); + $preview->setKeepAspect($keepAspect); + $preview->showPreview(); } diff --git a/lib/private/preview.php b/lib/private/preview.php index a586c94fd11..c7ef00652aa 100644 --- a/lib/private/preview.php +++ b/lib/private/preview.php @@ -200,14 +200,15 @@ class Preview { /** * set the path of the file you want a thumbnail from * @param string $file - * @return \OC\Preview $this + * @return $this */ public function setFile($file) { $this->file = $file; $this->info = null; + if ($file !== '') { $this->getFileInfo(); - if($this->info !== null && $this->info !== false) { + if($this->info instanceof \OCP\Files\FileInfo) { $this->mimeType = $this->info->getMimetype(); } }