ucla/mwf — Issue #16: Image class can be made to consume all available memory (up to php ini memory_limit setting)
Author: Trott
Created: 2011-11-06 20:06:07+00:00
State: open

The Image class doesn't take precautions to make sure it won't consume absurd amounts of memory before trying an operation. The result can be a PHP Fatal Error that makes the rest of the script fail to run.

Inserting this near the top of a script in the root dir (say, the default MWF index.php) will result in an error being logged and a blank page being rendered:

````require_once(dirname(__FILE__) . '/assets/lib/image.class.php');
ini_set('memory_limit','4M');
// Ironically, this 4.4 Mb image is named "thumbnail.jpg" http://xpress.sfsu.edu/specials/2010s/MOUSE/thumbnail.jpg
$image = Image::Factory('http://xpress.sfsu.edu/specials/2010s/MOUSE/thumbnail.jpg');
$image->set_max_height(100);
$image->generate_image();````

Given the likelihood that the images are from some external input (content in an RSS feed, comments from a user, or just something on an external server that we don't control and that someone else can swap in new content for at any time), it is probably wise to check the probable size of the operation and proceed only if the memory consumption seems reasonable.

This is all very similar to the (now-patched) bug in Mahara detailed at https://bugs.launchpad.net/mahara/+bug/784978. A bug fix for MWF would look very similar to that.