diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-07-21 15:08:50 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-07-21 15:09:39 +0100 |
commit | 6f79a7236f5018437caf084cef4dffa64ceba443 (patch) | |
tree | b0ecc0dc58e14fda5413b06261e64c2016ceecd2 /src/libmime | |
parent | 00a656be5aca1da4eaf46760b4ec26fe90a0cd0a (diff) | |
download | rspamd-6f79a7236f5018437caf084cef4dffa64ceba443.tar.gz rspamd-6f79a7236f5018437caf084cef4dffa64ceba443.zip |
[Feature] Add support to search archives by magic
Issue: #717
Reported by: @moisseev
Diffstat (limited to 'src/libmime')
-rw-r--r-- | src/libmime/archives.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/libmime/archives.c b/src/libmime/archives.c index b9a8f81b4..2bae067be 100644 --- a/src/libmime/archives.c +++ b/src/libmime/archives.c @@ -553,7 +553,8 @@ end: } static gboolean -rspamd_archive_cheat_detect (struct rspamd_mime_part *part, const gchar *str) +rspamd_archive_cheat_detect (struct rspamd_mime_part *part, const gchar *str, + const guchar *magic_start, gsize magic_len) { GMimeContentType *ct; const gchar *fname, *p; @@ -580,6 +581,13 @@ rspamd_archive_cheat_detect (struct rspamd_mime_part *part, const gchar *str) } } + if (magic_start != NULL) { + if (part->content->len > magic_len && memcmp (part->content->data, + magic_start, magic_len) == 0) { + return TRUE; + } + } + return FALSE; } @@ -588,15 +596,19 @@ rspamd_archives_process (struct rspamd_task *task) { guint i; struct rspamd_mime_part *part; + const guchar rar_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07}; + const guchar zip_magic[] = {0x50, 0x4b, 0x03, 0x04}; for (i = 0; i < task->parts->len; i ++) { part = g_ptr_array_index (task->parts, i); if (part->content->len > 0) { - if (rspamd_archive_cheat_detect (part, "zip")) { + if (rspamd_archive_cheat_detect (part, "zip", + zip_magic, sizeof (zip_magic))) { rspamd_archive_process_zip (task, part); } - else if (rspamd_archive_cheat_detect (part, "rar")) { + else if (rspamd_archive_cheat_detect (part, "rar", + rar_magic, sizeof (rar_magic))) { rspamd_archive_process_rar (task, part); } } |