]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Check min_bytes for images as well
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 1 Jun 2017 14:51:44 +0000 (15:51 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 1 Jun 2017 14:52:16 +0000 (15:52 +0100)
src/plugins/fuzzy_check.c

index f5cc61dc6e83dc87c5ceba9ef8e949fe51abb2d7..131500380e78bed7bd37b17dac2e4aba750fec90 100644 (file)
@@ -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);
-                                                                       }
-                                                               }
-                                                       }
                                                }
                                        }
                                }