]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Skip processing for large images
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 9 Dec 2016 13:02:03 +0000 (13:02 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 9 Dec 2016 13:02:03 +0000 (13:02 +0000)
src/libmime/images.c
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c

index 58e288bc55eda05928e47d6e2586ed50f900e375..454c1e5fd34322b55cf5b337c9a73a13c4af8ab2 100644 (file)
@@ -209,28 +209,6 @@ process_bmp_image (struct rspamd_task *task, GByteArray *data)
        return img;
 }
 
-#define SET_P(off_i, off_j) do { \
-       p[0] = (guint)gdImageGetPixel (dst, i + (off_i), j + (off_j)); \
-       p[1] = (guint)gdImageGetPixel (dst, i + (off_i), j + (off_j) + 1); \
-       p[2] = (guint)gdImageGetPixel (dst, i + (off_i), j + (off_j) + 2); \
-       p[3] = (guint)gdImageGetPixel (dst, i + (off_i), j + (off_j) + 3); \
-       p[4] = (guint)gdImageGetPixel (dst, i + (off_i) + 1, j + (off_j)); \
-       p[5] = (guint)gdImageGetPixel (dst, i + (off_i) + 1, j + (off_j) + 1); \
-       p[6] = (guint)gdImageGetPixel (dst, i + (off_i) + 1, j + (off_j) + 2); \
-       p[7] = (guint)gdImageGetPixel (dst, i + (off_i) + 1, j + (off_j) + 3); \
-} while (0)
-
-#define SET_N() do { \
-       n += (guint) ((gint)p[0] - navg); \
-       n += (guint) ((gint)p[1] - navg); \
-       n += (guint) ((gint)p[2] - navg); \
-       n += (guint) ((gint)p[3] - navg); \
-       n += (guint) ((gint)p[4] - navg); \
-       n += (guint) ((gint)p[5] - navg); \
-       n += (guint) ((gint)p[6] - navg); \
-       n += (guint) ((gint)p[7] - navg); \
-} while (0)
-
 #ifdef WITH_GD
 /*
  * DCT from Emil Mikulic.
@@ -475,8 +453,6 @@ rspamd_image_normalize (struct rspamd_task *task, struct rspamd_image *img)
 #endif
 }
 
-#undef SET_P
-
 static void
 process_image (struct rspamd_task *task, struct rspamd_mime_part *part)
 {
@@ -516,7 +492,14 @@ process_image (struct rspamd_task *task, struct rspamd_mime_part *part)
                        task->message_id);
                img->filename = part->filename;
                img->parent = part;
-               rspamd_image_normalize (task, img);
+
+               if (img->data->len <= task->cfg->max_pic_size) {
+                       rspamd_image_normalize (task, img);
+               }
+               else {
+                       msg_info_task ("skip normalization for image %s: too large: %z",
+                                       img->filename, img->data->len);
+               }
                part->flags |= RSPAMD_MIME_PART_IMAGE;
                part->specific_data = img;
 
index ccd1d41edc649b1335e39687da66876b127b213e..2ce4bcb281a05d91d5038f15c732f6f6e1df8356 100644 (file)
@@ -310,6 +310,7 @@ struct rspamd_config {
        gsize max_cores_count;                          /**< maximum number of core files                                               */
        gchar *cores_dir;                               /**< directory for core files                                                   */
        gsize max_message;                              /**< maximum size for messages                                                  */
+       gsize max_pic_size;                             /**< maximum size for a picture to process                              */
 
        enum rspamd_log_type log_type;                  /**< log type                                                                                   */
        gint log_facility;                              /**< log facility in case of syslog                                             */
index 282ae7469d8b673662daab8f53ff8457287408bd..42e406231abf352c1049f1e86ca7c6027747101f 100644 (file)
@@ -2015,7 +2015,13 @@ rspamd_rcl_config_init (struct rspamd_config *cfg)
                        rspamd_rcl_parse_struct_integer,
                        G_STRUCT_OFFSET (struct rspamd_config, max_message),
                        RSPAMD_CL_FLAG_INT_SIZE,
-                       "Maximum size of the message to be scanned");
+                       "Maximum size of the message to be scanned (50Mb by default)");
+       rspamd_rcl_add_default_handler (sub,
+                       "max_pic",
+                       rspamd_rcl_parse_struct_integer,
+                       G_STRUCT_OFFSET (struct rspamd_config, max_pic_size),
+                       RSPAMD_CL_FLAG_INT_SIZE,
+                       "Maximum size of the picture to be normalized (1Mb by default)");
        rspamd_rcl_add_default_handler (sub,
                        "zstd_input_dictionary",
                        rspamd_rcl_parse_struct_string,
index a00a1665cd1493e87cb4eb9455bc7581474021e0..2ead99f32f6a1b88f3c6bd905035c083306714c4 100644 (file)
@@ -40,6 +40,7 @@
 #define DEFAULT_MAX_WORD 40
 #define DEFAULT_WORDS_DECAY 200
 #define DEFAULT_MAX_MESSAGE (50 * 1024 * 1024)
+#define DEFAULT_MAX_PIC (1 * 1024 * 1024)
 
 struct rspamd_ucl_map_cbdata {
        struct rspamd_config *cfg;
@@ -171,6 +172,7 @@ rspamd_config_new (void)
 
        cfg->ssl_ciphers = "HIGH:!aNULL:!kRSA:!PSK:!SRP:!MD5:!RC4";
        cfg->max_message = DEFAULT_MAX_MESSAGE;
+       cfg->max_pic_size = DEFAULT_MAX_PIC;
        cfg->monitored_ctx = rspamd_monitored_ctx_init ();
 #ifdef WITH_HIREDIS
        cfg->redis_pool = rspamd_redis_pool_init ();