commit b32d6cd: [Minor] Lua_magic: Improve hyperscan usage

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Sep 24 08:28:07 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-09-24 09:26:04 +0100
URL: https://github.com/rspamd/rspamd/commit/b32d6cde09df0e45c178623888d4249102cd054f (HEAD -> master)

[Minor] Lua_magic: Improve hyperscan usage

---
 lualib/lua_magic/heuristics.lua |  5 ++++-
 lualib/lua_magic/init.lua       | 11 +++++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/lualib/lua_magic/heuristics.lua b/lualib/lua_magic/heuristics.lua
index 04c89ba69..8fb83bb0d 100644
--- a/lualib/lua_magic/heuristics.lua
+++ b/lualib/lua_magic/heuristics.lua
@@ -95,7 +95,10 @@ local function compile_tries()
       end
     end
 
-    return rspamd_trie.create(strs, rspamd_trie.flags.re)
+    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)
   end
 
   if not msoffice_trie then
diff --git a/lualib/lua_magic/init.lua b/lualib/lua_magic/init.lua
index 2fb848707..d92980246 100644
--- a/lualib/lua_magic/init.lua
+++ b/lualib/lua_magic/init.lua
@@ -126,18 +126,21 @@ local function process_patterns(log_obj)
         end
       end
     end
-
+    local bit = require "bit"
+    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)
     compiled_patterns = rspamd_trie.create(fun.totable(
         fun.map(function(t) return t[1] end, processed_patterns)),
-        rspamd_trie.flags.re
+        compile_flags
     )
     compiled_short_patterns = rspamd_trie.create(fun.totable(
         fun.map(function(t) return t[1] end, short_patterns)),
-        rspamd_trie.flags.re
+        compile_flags
     )
     compiled_tail_patterns = rspamd_trie.create(fun.totable(
         fun.map(function(t) return t[1] end, tail_patterns)),
-        rspamd_trie.flags.re
+        compile_flags
     )
 
     lua_util.debugm(N, log_obj,


More information about the Commits mailing list