summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSimon Spannagel <simonspa@kth.se>2021-08-18 07:36:11 +0200
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2021-08-18 15:42:52 +0000
commitcb49f193850838a26e8097b26708bc19fb0fe06f (patch)
tree7d15847c5e70730a8d7cd037a3aa648a3a9ebf56 /lib
parente1d9a45c6d5d68f8ea97cbdc6a8e23403d795c25 (diff)
downloadnextcloud-server-cb49f193850838a26e8097b26708bc19fb0fe06f.tar.gz
nextcloud-server-cb49f193850838a26e8097b26708bc19fb0fe06f.zip
Fix #20913: Check image resource before attempting to preserve alpha
Signed-off-by: Simon Spannagel <simonspa@kth.se>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/legacy/OC_Image.php20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/private/legacy/OC_Image.php b/lib/private/legacy/OC_Image.php
index 59d51773528..890df2241af 100644
--- a/lib/private/legacy/OC_Image.php
+++ b/lib/private/legacy/OC_Image.php
@@ -562,9 +562,13 @@ class OC_Image implements \OCP\IImage {
case IMAGETYPE_GIF:
if (imagetypes() & IMG_GIF) {
$this->resource = imagecreatefromgif($imagePath);
- // Preserve transparency
- imagealphablending($this->resource, true);
- imagesavealpha($this->resource, true);
+ if ($this->resource) {
+ // Preserve transparency
+ imagealphablending($this->resource, true);
+ imagesavealpha($this->resource, true);
+ } else {
+ $this->logger->debug('OC_Image->loadFromFile, GIF image not valid: ' . $imagePath, ['app' => 'core']);
+ }
} else {
$this->logger->debug('OC_Image->loadFromFile, GIF images not supported: ' . $imagePath, ['app' => 'core']);
}
@@ -583,9 +587,13 @@ class OC_Image implements \OCP\IImage {
case IMAGETYPE_PNG:
if (imagetypes() & IMG_PNG) {
$this->resource = @imagecreatefrompng($imagePath);
- // Preserve transparency
- imagealphablending($this->resource, true);
- imagesavealpha($this->resource, true);
+ if ($this->resource) {
+ // Preserve transparency
+ imagealphablending($this->resource, true);
+ imagesavealpha($this->resource, true);
+ } else {
+ $this->logger->debug('OC_Image->loadFromFile, PNG image not valid: ' . $imagePath, ['app' => 'core']);
+ }
} else {
$this->logger->debug('OC_Image->loadFromFile, PNG images not supported: ' . $imagePath, ['app' => 'core']);
}