Page 1 of 1

image helper bug

Posted: Mon Aug 17, 2009 12:52 pm
by Qphoria
In the image helper class there is a check at the top:

Code: Select all

if (!file_exists(DIR_IMAGE . $filename)) {
	return;
}
The problem is that even if $filename = "", that will still return true and try to resize a nameless image and throw an error:

Code: Select all

<b>Warning</b>:  getimagesize(D:\EasyWAMP\www\v132/image/) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: Permission denied in <b>D:\EasyWAMP\www\v132\system\library\image.php</b> on line <b>11</b><br />
file_exists sees that the DIR_IMAGE path exists and that is enough to pass as TRUE as stated in the php manual:
Returns TRUE if the file or directory specified by filename exists; FALSE otherwise.
This should work better:

Code: Select all

if ($filename == "" || !file_exists(DIR_IMAGE . $filename)) {
	return;
}

Re: image helper bug

Posted: Mon Aug 17, 2009 2:51 pm
by stefan_m
hello,
To check only a regular file for existence use "is_file"(http://www.php.net/is_file)

Code: Select all

if (!is_file(DIR_IMAGE . $filename)) {
   return;
}
ciao, Stefan

EDIT: file_exists is used in several files with the intension to check file existence... looks susceptible for the same error.

Code: Select all

$file = DIR_SYSTEM . 'library/' . $library . '.php';
		
if (file_exists($file)) {
    include_once($file);
} else {
    exit('Error: Could not load library ' . $library . '!');
}
Ok, the suffix do the job to turn this to false if $library is empty, but the check itself is not the right way in this case... in my opinion and i wont be a wisenheimer... :-) however it works.

Re: image helper bug

Posted: Mon Aug 17, 2009 8:09 pm
by Qphoria
OMG YOU'RE SUCH A WISENHEIMER! ;D ;D
But you are correct. There are a lot of place that need a better check for existence.