diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-10-18 18:31:46 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-10-18 18:31:46 +0100 |
commit | 31138dd8acc790c0129fb488584311c85c96f87c (patch) | |
tree | 14e5638d60375dfe27caf72ec7711eb99e0b9663 /lualib/lua_meta.lua | |
parent | 88fb22db06f44363acf3b61f2635473f7102a0f3 (diff) | |
download | rspamd-31138dd8acc790c0129fb488584311c85c96f87c.tar.gz rspamd-31138dd8acc790c0129fb488584311c85c96f87c.zip |
[Fix] Neural: Add protection agains infinities
Diffstat (limited to 'lualib/lua_meta.lua')
-rw-r--r-- | lualib/lua_meta.lua | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lualib/lua_meta.lua b/lualib/lua_meta.lua index 984f5fec8..3ed416158 100644 --- a/lualib/lua_meta.lua +++ b/lualib/lua_meta.lua @@ -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 |