]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Adjust length of the fuzzy checks for short text parts
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 2 Aug 2022 20:12:38 +0000 (21:12 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 2 Aug 2022 20:12:38 +0000 (21:12 +0100)
Reported by: @citrin

lualib/lua_fuzzy.lua
src/lua/lua_mimepart.c

index 1f82752f90f790ca3961f385a9f330783d45bd9c..ce4ac55ee7f67c7761f0787f6d3d0a6929e6ff14 100644 (file)
@@ -126,7 +126,11 @@ local function check_length(task, part, rule)
     local adjusted_bytes = bytes
 
     if part:is_text() then
-      bytes = part:get_text():get_length()
+      -- Fuzzy plugin uses stripped utf content to get an exact hash, that
+      -- corresponds to `get_content_oneline()`
+      -- However, in the case of empty parts this method returns `nil`, so extra
+      -- sanity check is required.
+      bytes = #(part:get_text():get_content_oneline() or '')
       if rule.text_multiplier then
         adjusted_bytes = bytes * rule.text_multiplier
       end
index ae959c34e494a3ffe89b98c89a69ac51215e566d..459a78e69b4cbbb4f1cb27a5f4448aa490ff2176 100644 (file)
@@ -803,11 +803,7 @@ lua_textpart_get_content_oneline (lua_State * L)
                return 1;
        }
 
-       t = lua_newuserdata (L, sizeof (*t));
-       rspamd_lua_setclass (L, "rspamd{text}", -1);
-       t->start = part->utf_stripped_content->data;
-       t->len = part->utf_stripped_content->len;
-       t->flags = 0;
+       lua_new_text(L, part->utf_stripped_content->data, part->utf_stripped_content->len, FALSE);
 
        return 1;
 }