]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Neural: Add protection agains infinities
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 18 Oct 2019 17:31:46 +0000 (18:31 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 18 Oct 2019 17:31:46 +0000 (18:31 +0100)
lualib/lua_meta.lua
src/lua/lua_task.c

index 984f5fec8d168a7cb05f08fdfa345d94a2d4effc..3ed4161581cae3f1338a12cef16b96da6550f1ec 100644 (file)
@@ -181,9 +181,11 @@ local function meta_received_function(task)
     end,
     fun.filter(function(rc) return not rc.flags or not rc.flags['artificial'] end, rh))
 
-    invalid_factor = invalid_factor / ntotal
-    secure_factor = secure_factor / ntotal
-    count_factor = 1.0 / ntotal
+    if ntotal > 0 then
+      invalid_factor = invalid_factor / ntotal
+      secure_factor = secure_factor / ntotal
+      count_factor = 1.0 / ntotal
+    end
 
     if time_factor ~= 0 then
       time_factor = 1.0 / time_factor
@@ -194,8 +196,9 @@ local function meta_received_function(task)
 end
 
 local function meta_urls_function(task)
-  if task:has_urls() then
-    return {1.0 / #(task:get_urls())}
+  local has_urls,nurls = task:has_urls()
+  if has_urls and nurls > 0 then
+    return {1.0 / nurls}
   end
 
   return {0}
@@ -481,6 +484,13 @@ local function rspamd_gen_metatokens_table(task)
   for _,mt in ipairs(metafunctions) do
     local ct = mt.cb(task)
     for i,tok in ipairs(ct) do
+      if tok ~= tok or tok == math.huge() then
+        local logger = require "rspamd_logger"
+        logger.errx(task, 'metatoken %s returned %s; replace it with 0 for sanity',
+            mt.names[i], tok)
+        tok = 0.0
+      end
+
       metatokens[mt.names[i]] = tok
     end
   end
index 5be5b3f9452a97fd14ced3bad28acbf84239b7d5..263aa83fa6a30393ac73548194fb9d3fb11caba6 100644 (file)
@@ -4667,7 +4667,7 @@ lua_task_process_ann_tokens (lua_State *L)
                        sres = rspamd_task_find_symbol_result (task, sym);
 
                        if (sres && !(sres->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) {
-                               if (!isnan (sres->score) &&
+                               if (!isnan (sres->score) && !isinf (sres->score) &&
                                        !(rspamd_symcache_item_flags (sres->sym->cache_item) &
                                          SYMBOL_TYPE_NOSTAT)) {