diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2017-05-02 21:49:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-02 21:49:14 +0200 |
commit | 24ff230f938bb9c47bbd75a133af84314b42aca7 (patch) | |
tree | 6919c65502964fea435abe070d0e544dae6e38dd /lib | |
parent | 34b8ea6ebf0cbe873804e1fb8d7d87859d3bb8e9 (diff) | |
parent | 2847e9f2e3e5f338ba1b727ea207b2c549d38e92 (diff) | |
download | nextcloud-server-24ff230f938bb9c47bbd75a133af84314b42aca7.tar.gz nextcloud-server-24ff230f938bb9c47bbd75a133af84314b42aca7.zip |
Merge pull request #4620 from nextcloud/preview-error-handling
better handling of preview generation errors
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Preview/Generator.php | 7 | ||||
-rw-r--r-- | lib/private/PreviewManager.php | 3 | ||||
-rw-r--r-- | lib/private/legacy/image.php | 8 | ||||
-rw-r--r-- | lib/public/IPreview.php | 3 |
4 files changed, 15 insertions, 6 deletions
diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index fd75e51b638..5a264c2bbd5 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -84,6 +84,7 @@ class Generator { * @param string $mimeType * @return ISimpleFile * @throws NotFoundException + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) */ public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) { $this->eventDispatcher->dispatch( @@ -299,10 +300,15 @@ class Generator { * @param int $maxHeight * @return ISimpleFile * @throws NotFoundException + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) */ private function generatePreview(ISimpleFolder $previewFolder, ISimpleFile $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight) { $preview = $this->helper->getImage($maxPreview); + if (!$preview->valid()) { + throw new \InvalidArgumentException('Failed to generate preview, failed to load image'); + } + if ($crop) { if ($height !== $preview->height() && $width !== $preview->width()) { //Resize @@ -325,6 +331,7 @@ class Generator { $preview->resize(max($width, $height)); } + $path = $this->generatePath($width, $height, $crop); try { $file = $previewFolder->newFile($path); diff --git a/lib/private/PreviewManager.php b/lib/private/PreviewManager.php index 8c5a7ad29f1..12fcc292c63 100644 --- a/lib/private/PreviewManager.php +++ b/lib/private/PreviewManager.php @@ -182,7 +182,8 @@ class PreviewManager implements IPreview { * @param string $mimeType * @return ISimpleFile * @throws NotFoundException - * @since 11.0.0 + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) + * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0 */ public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) { if ($this->generator === null) { diff --git a/lib/private/legacy/image.php b/lib/private/legacy/image.php index e26148bdf15..120b19d1cff 100644 --- a/lib/private/legacy/image.php +++ b/lib/private/legacy/image.php @@ -563,7 +563,7 @@ class OC_Image implements \OCP\IImage { case IMAGETYPE_JPEG: if (imagetypes() & IMG_JPG) { if (getimagesize($imagePath) !== false) { - $this->resource = imagecreatefromjpeg($imagePath); + $this->resource = @imagecreatefromjpeg($imagePath); } else { $this->logger->debug('OC_Image->loadFromFile, JPG image not valid: ' . $imagePath, array('app' => 'core')); } @@ -573,7 +573,7 @@ class OC_Image implements \OCP\IImage { break; case IMAGETYPE_PNG: if (imagetypes() & IMG_PNG) { - $this->resource = imagecreatefrompng($imagePath); + $this->resource = @imagecreatefrompng($imagePath); // Preserve transparency imagealphablending($this->resource, true); imagesavealpha($this->resource, true); @@ -583,14 +583,14 @@ class OC_Image implements \OCP\IImage { break; case IMAGETYPE_XBM: if (imagetypes() & IMG_XPM) { - $this->resource = imagecreatefromxbm($imagePath); + $this->resource = @imagecreatefromxbm($imagePath); } else { $this->logger->debug('OC_Image->loadFromFile, XBM/XPM images not supported: ' . $imagePath, array('app' => 'core')); } break; case IMAGETYPE_WBMP: if (imagetypes() & IMG_WBMP) { - $this->resource = imagecreatefromwbmp($imagePath); + $this->resource = @imagecreatefromwbmp($imagePath); } else { $this->logger->debug('OC_Image->loadFromFile, WBMP images not supported: ' . $imagePath, array('app' => 'core')); } diff --git a/lib/public/IPreview.php b/lib/public/IPreview.php index 207539b1170..7705df61a17 100644 --- a/lib/public/IPreview.php +++ b/lib/public/IPreview.php @@ -104,7 +104,8 @@ interface IPreview { * @param string $mimeType To force a given mimetype for the file (files_versions needs this) * @return ISimpleFile * @throws NotFoundException - * @since 11.0.0 + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) + * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0 */ public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null); |