]> source.dussan.org Git - nextcloud-server.git/commitdiff
better handling of preview generation errors
authorRobin Appelman <robin@icewind.nl>
Mon, 1 May 2017 12:03:00 +0000 (14:03 +0200)
committerRobin Appelman <robin@icewind.nl>
Tue, 2 May 2017 11:43:47 +0000 (13:43 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Preview/Generator.php
lib/private/legacy/image.php

index fd75e51b63881fb480ddae476174633f12bd398d..0fb284259aa8bf477d5e4d256f9d1f2d0261a092 100644 (file)
@@ -303,6 +303,10 @@ class Generator {
        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 +329,7 @@ class Generator {
                        $preview->resize(max($width, $height));
                }
 
+
                $path = $this->generatePath($width, $height, $crop);
                try {
                        $file = $previewFolder->newFile($path);
index e26148bdf15b783894088593e4a7b2c6c394622d..120b19d1cff12c37f827066631c038ec5c4abca3 100644 (file)
@@ -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'));
                                }