summaryrefslogtreecommitdiff
path: root/program/lib/Roundcube
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-11-03 15:49:49 +0100
committerThomas Bruederli <bruederli@kolabsys.com>2014-11-03 15:49:49 +0100
commit5c9ddcc052cb95c6bb1ae64e5bb36a3564414442 (patch)
tree5a34dd804e65ace4ea314a45c050d5d7ae5209cd /program/lib/Roundcube
parenta63b9b546c699e1f14ed26e18834b163360ba2c8 (diff)
Check available memory for image resizing with GD on Windows (#1489937)
Diffstat (limited to 'program/lib/Roundcube')
-rw-r--r--program/lib/Roundcube/rcube_image.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/program/lib/Roundcube/rcube_image.php b/program/lib/Roundcube/rcube_image.php
index 77ce1647d..9c9f08b53 100644
--- a/program/lib/Roundcube/rcube_image.php
+++ b/program/lib/Roundcube/rcube_image.php
@@ -59,11 +59,13 @@ class rcube_image
$height = $imsize[1];
$gd_type = $imsize['2'];
$type = image_type_to_extension($imsize['2'], false);
+ $channels = $imsize['channels'];
}
// use ImageMagick
if (!$type && ($data = $this->identify())) {
list($type, $width, $height) = $data;
+ $channels = null;
}
if ($type) {
@@ -72,8 +74,11 @@ class rcube_image
'gd_type' => $gd_type,
'width' => $width,
'height' => $height,
+ 'channels' => $channels,
);
}
+
+ return null;
}
/**
@@ -181,6 +186,11 @@ class rcube_image
}
}
+ // do we have enough memory? (#1489937)
+ if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' && !$this->mem_check($props)) {
+ return false;
+ }
+
// use GD extension
if ($props['gd_type']) {
if ($props['gd_type'] == IMAGETYPE_JPEG && function_exists('imagecreatefromjpeg')) {
@@ -327,6 +337,12 @@ class rcube_image
// use GD extension (TIFF isn't supported)
$props = $this->props();
+ // do we have enough memory? (#1489937)
+ if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' && !$this->mem_check($props)) {
+ return false;
+ }
+
+
if ($props['gd_type']) {
if ($props['gd_type'] == IMAGETYPE_JPEG && function_exists('imagecreatefromjpeg')) {
$image = imagecreatefromjpeg($this->image_file);
@@ -406,4 +422,22 @@ class rcube_image
catch (Exception $e) {}
}
}
+
+ /**
+ * Check if we have enough memory to load specified image
+ */
+ private function mem_check($props)
+ {
+ // image size is unknown, we can't calculate required memory
+ if (!$props['width']) {
+ return true;
+ }
+
+ // channels: CMYK - 4, RGB - 3
+ $multip = ($props['channels'] ?: 3) + 1;
+
+ // calculate image size in memory (in bytes)
+ $size = $props['width'] * $props['height'] * $multip;
+ return rcube_utils::mem_check($size);
+ }
}