From: Vsevolod Stakhov Date: Thu, 1 Jun 2017 14:51:44 +0000 (+0100) Subject: [Fix] Check min_bytes for images as well X-Git-Tag: 1.6.0~83 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6643ba1ce08dfb96b498d4a809d6013c0648fe92;p=rspamd.git [Fix] Check min_bytes for images as well --- diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index f5cc61dc6..131500380 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -2349,13 +2349,49 @@ fuzzy_generate_commands (struct rspamd_task *task, struct fuzzy_rule *rule, image = mime_part->specific.img; if (image->data->len > 0) { - if (fuzzy_module_ctx->min_height <= 0 || image->height >= - fuzzy_module_ctx->min_height) { - if (fuzzy_module_ctx->min_width <= 0 || image->width >= - fuzzy_module_ctx->min_width) { - io = fuzzy_cmd_from_data_part (rule, c, flag, value, + /* Check: + * - min height + * - min width + * - min bytes + */ + + if ((fuzzy_module_ctx->min_height == 0 || + image->height >= fuzzy_module_ctx->min_height) && + (fuzzy_module_ctx->min_width == 0 || + image->width >= fuzzy_module_ctx->min_width) && + (fuzzy_module_ctx->min_bytes <= 0 || + mime_part->parsed_data.len >= fuzzy_module_ctx->min_bytes)) { + io = fuzzy_cmd_from_data_part (rule, c, flag, value, + task->task_pool, + image->parent->digest); + if (io) { + gboolean skip_existing = FALSE; + + PTR_ARRAY_FOREACH (res, j, cur) { + if (memcmp (cur->cmd.digest, io->cmd.digest, + sizeof (io->cmd.digest)) == 0) { + skip_existing = TRUE; + break; + } + } + + if (!skip_existing) { + g_ptr_array_add (res, io); + } + } + + if (rule->fuzzy_images) { + /* Try to normalize image */ + if (!image->is_normalized) { + rspamd_image_normalize (task, image); + } + } + + if (image->is_normalized) { + io = fuzzy_cmd_from_image_part (rule, c, flag, + value, task->task_pool, - image->parent->digest); + image); if (io) { gboolean skip_existing = FALSE; @@ -2371,34 +2407,6 @@ fuzzy_generate_commands (struct rspamd_task *task, struct fuzzy_rule *rule, g_ptr_array_add (res, io); } } - - if (rule->fuzzy_images) { - /* Try to normalize image */ - if (!image->is_normalized) { - rspamd_image_normalize (task, image); - } - } - - if (image->is_normalized) { - io = fuzzy_cmd_from_image_part (rule, c, flag, value, - task->task_pool, - image); - if (io) { - gboolean skip_existing = FALSE; - - PTR_ARRAY_FOREACH (res, j, cur) { - if (memcmp (cur->cmd.digest, io->cmd.digest, - sizeof (io->cmd.digest)) == 0) { - skip_existing = TRUE; - break; - } - } - - if (!skip_existing) { - g_ptr_array_add (res, io); - } - } - } } } }