]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Lua_magic: Add images patterns
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 24 Sep 2019 14:43:04 +0000 (15:43 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 24 Sep 2019 14:43:04 +0000 (15:43 +0100)
lualib/lua_magic/heuristics.lua
lualib/lua_magic/patterns.lua

index 70093205119dfaaba1179c579e459c6ab76b8b9c..fb105932a7cd8d2e29f9348f2ef385a9ef5ae8e6 100644 (file)
@@ -303,15 +303,6 @@ local function detect_archive_flaw(part, arch, log_obj)
 end
 
 exports.mime_part_heuristic = function(part, log_obj)
-
-  if part:is_image() then
-    local img = part:get_image()
-    local img_type = img:get_type():lower()
-
-    if img_type == 'jpeg' then img_type = 'jpg' end
-    return img_type,60
-  end
-
   if part:is_archive() then
     local arch = part:get_archive()
     return detect_archive_flaw(part, arch, log_obj)
index d9604b714665463660cafdffdac3c5d144b68ee7..8d90a45efd2032471eec489c09f47682f1a5e0f5 100644 (file)
@@ -380,6 +380,47 @@ local patterns = {
       }
     }
   },
+  jpg = {
+    matches = {
+      { -- JPEG2000
+        hex = [[0000000c6a5020200d0a870a]],
+        relative_position = 0,
+        weight = 60,
+      },
+      {
+        string = [[^\x{ff}\x{d8}\x{ff}(?:[\x{e0}\x{e1}])]],
+        weight = 60,
+        position = 4,
+      },
+    },
+  },
+  png = {
+    matches = {
+      {
+        string = [[^\x{89}PNG\x{0d}\x{0a}\x{1a}\x{0a}]],
+        position = 8,
+        weight = 60,
+      },
+    }
+  },
+  gif = {
+    matches = {
+      {
+        string = [[^GIF8\d]],
+        position = 5,
+        weight = 60,
+      },
+    }
+  },
+  bmp = {
+    matches = {
+      {
+        string = [[^BM...\x{00}\x{00}\x{00}\x{00}]],
+        position = 9,
+        weight = 60,
+      },
+    }
+  },
 }
 
 return patterns
\ No newline at end of file