From 9f1c041a0c958a69bfb44e09d883628c2c97d00e Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sat, 16 May 2009 22:38:41 +0000 Subject: checking approx size in memory to prevent WSOD on resize operations - this is using a very rough estimate --- actions/upload.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'actions/upload.php') diff --git a/actions/upload.php b/actions/upload.php index bb59a45a1..8015a2ae8 100644 --- a/actions/upload.php +++ b/actions/upload.php @@ -66,11 +66,26 @@ continue; } - // make sure file does not exceed limit + // make sure file does not exceed memory limit if ($sent_file['size'] > $maxfilesize) { array_push($not_uploaded, $sent_file['name']); continue; } + + // make sure the in memory image size does not exceed memory available - GD only + $imginfo = getimagesize($sent_file['tmp_name']); + $mem_required = 5 * $imginfo[0] * $imginfo[1]; + $mem_avail = ini_get('memory_limit'); + $mem_avail = rtrim($mem_avail, 'M'); + $mem_avail = $mem_avail * 1024 * 1024; + $mem_avail = $mem_avail - memory_get_peak_usage() - 4194304; // 4 MB buffer + //error_log($mem_required); + //error_log($mem_avail); + if ($image_lib === 'GD' && $mem_required > $mem_avail) { + array_push($not_uploaded, $sent_file['name']); + trigger_error('Tidypics error: image memory size too large for resizing so rejecting', E_USER_WARNING); + continue; + } //this will save to users folder in /image/ and organize by photo album $prefix = "image/" . $container_guid . "/"; -- cgit v1.2.3