Dear developer team,
I noticed that nowhere in the code a validation of the uploaded file is done if it's really an image file or not. It's also possible to upload a file (.pdf) which was renamed to .jpg, for example ;-)
Here are the responsible lines which could be expanded as follows:
<?php
/**
* Get the upload validators for an image field.
*
* @param $field CCK Field
* @return array suitable for passing to file_save_upload() or the filefield
* element's '#upload_validators' property.
*/
function imagefield_widget_upload_validators($field) {
$validators = array();
if (!empty($field['widget']['max_resolution']) || !empty($field['widget']['min_resolution'])) {
$validators['filefield_validate_image_resolution'] = array(
$field['widget']['max_resolution'],
$field['widget']['min_resolution'],
);
}
$validators['file_validate_is_image'] = array(); // check if it's a real image file
return $validators;
}
?>
Yours sincerely,
grandcat (developer of image fupload, soon with imagefield support =)
Comments
Comment #1
grandcat commentedBetter replacement:
But it still throws the following error message:
Argument "size" is missing, but I can't really recognize a sence of the need of this argument? See patch below which fixes this behaviour.
Comment #2
drewish commentedplease post patches rather than code snippets. I think this is by design so that the field can accept rig and other formats that cannot be displayed by most browsers. That said with the new mime detection features we should be limiting it to image/* files.
Comment #3
grandcat commentedIf a user doesn't want to install mimedetect, it falls back to function "file_get_mimetype", but only the file extension is checked. So, a renamed file could also be uploaded!
It's clear that a renamed PDF File can't be displayed as JPG, but this can become a security hole in future, so I advice you to add an additional validation function. This does not cost anything ;-)
I also added a patch for filefield which is needed to prevent an error message.
Comment #4
grandcat commentedForgot to set status =/
Comment #5
drewish commentedi'm not sure why the filefield.module patch is needed...
Comment #6
drewish commentedah, fixed the filefield portion of the issue with #300619: filefield_validate_is_image_help() should not have any parameters. committed the addition of the is_image validator.
Comment #7
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.