commit 2568de9: [Minor] Lua_magic: Fix csv detection

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Oct 7 13:56:08 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-10-07 14:54:34 +0100
URL: https://github.com/rspamd/rspamd/commit/2568de9762f9244c2d442719a6ec20600e241333 (HEAD -> master)

[Minor] Lua_magic: Fix csv detection

---
 lualib/lua_magic/heuristics.lua | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/lualib/lua_magic/heuristics.lua b/lualib/lua_magic/heuristics.lua
index 07b1ef76a..3da6a84ab 100644
--- a/lualib/lua_magic/heuristics.lua
+++ b/lualib/lua_magic/heuristics.lua
@@ -72,7 +72,7 @@ local txt_patterns = {
     [[(?i)\s*<span]],
   },
   csv = {
-    [[(?:[-a-zA-Z0-9_]+\s*,){2,}(?:[-a-zA-Z0-9_]+[\r\n])]]
+    [[(?:[-a-zA-Z0-9_]+\s*,){2,}(?:[-a-zA-Z0-9_]+,?[ ]*[\r\n])]]
   },
 }
 
@@ -85,7 +85,11 @@ local txt_patterns_indexes = {}
 local exports = {}
 
 local function compile_tries()
-  local function compile_pats(patterns, indexes, transform_func)
+  local default_compile_flags = bit.bor(rspamd_trie.flags.re,
+      rspamd_trie.flags.dot_all,
+      rspamd_trie.flags.single_match,
+      rspamd_trie.flags.no_start)
+  local function compile_pats(patterns, indexes, transform_func, compile_flags)
     local strs = {}
     for ext,pats in pairs(patterns) do
       for _,pat in ipairs(pats) do
@@ -95,10 +99,7 @@ local function compile_tries()
       end
     end
 
-    local compile_flags = bit.bor(rspamd_trie.flags.re, rspamd_trie.flags.dot_all)
-    compile_flags = bit.bor(compile_flags, rspamd_trie.flags.single_match)
-    compile_flags = bit.bor(compile_flags, rspamd_trie.flags.no_start)
-    return rspamd_trie.create(strs, compile_flags)
+    return rspamd_trie.create(strs, compile_flags or default_compile_flags)
   end
 
   if not msoffice_trie then
@@ -130,7 +131,10 @@ local function compile_tries()
         function(pat) return pat end)
     -- Text patterns at the initial fragment
     txt_trie = compile_pats(txt_patterns, txt_patterns_indexes,
-        function(pat) return pat end)
+        function(pat) return pat end,
+        bit.bor(rspamd_trie.flags.re,
+            rspamd_trie.flags.dot_all,
+            rspamd_trie.flags.no_start))
   end
 end
 
@@ -391,8 +395,8 @@ exports.text_part_heuristic = function(part, log_obj)
           local ext = txt_patterns_indexes[n]
           if ext then
             res[ext] = (res[ext] or 0) + 20 * #positions
-            lua_util.debugm(N, log_obj, "found txt pattern for %s: %s",
-                ext, #positions)
+            lua_util.debugm(N, log_obj, "found txt pattern for %s: %s, total: %s",
+                ext, #positions, res[ext])
           end
         end
 


More information about the Commits mailing list