Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter’s Image Manipulation class runs methods even after initialization failed
#1

[eluser]section31[/eluser]
I tried ci's image_lib for the first time and I noticed even after the initialize method returns false, some methods still return true.

Test Case:
initialize fails due to invalid path or something similar, so the properties aren't set which are required for most of the methods.

running the image_process_gd('crop') method runs and returns true here
Code:
// If the target width/height match the source then it's pointless to crop, right?
if ($this->width >= $this->orig_width AND $this->height >= $this->orig_height)
{
    // We'll return true so the user thinks the process succeeded.
    // It'll be our little secret...
    
    return TRUE;
}

Why: The reason it returns true is because the used properties are defaulted to '' and when evaluated like this, they are converted to integers which is 0 making it.

Code:
// If the target width/height match the source then it's pointless to crop, right?
if (0 >= 0 AND 0 >= 0)
{

I sure hope it's not assumed that we are responsible to check for errors after every initialization before we run any methods. Also, shouldn't the error_msg property be cleared and set to array() after every start of initialization in case you want to run several methods on different images and keep the errors separate.

I haven't put much thought of a fix for this, but wouldn't simply checking if the error_msg array is empty inside each of 4 processing functions suffice.
#2

[eluser]Derek Allard[/eluser]
sounds like a nice catch. I'm moving this into the bug forum. If anyone does further checking, please report here and I'll see it gets resolved.
#3

[eluser]section31[/eluser]
I also don't see a check to see if the destination file is writable.

Will only take up a few lines in the initialize method.

Add this on line 240something right after $this->dest_image and $this->dest_folder are set.
Code:
if (!is_writable($this->dest_folder) && (!file_exists($this->dest_folder . $this->dest_image) || !is_writable($this->dest_folder . $this->dest_image))) {
    $this->set_error("The Destination File is not Writable.");
    return false;
}




Theme © iAndrew 2016 - Forum software by © MyBB