From 2249d428bd8f27d8e952233c4a15a75f69b12316 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 2 Aug 2022 21:12:38 +0100 Subject: [PATCH] [Fix] Adjust length of the fuzzy checks for short text parts Reported by: @citrin --- lualib/lua_fuzzy.lua | 6 +++++- src/lua/lua_mimepart.c | 6 +----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lualib/lua_fuzzy.lua b/lualib/lua_fuzzy.lua index 1f82752f9..ce4ac55ee 100644 --- a/lualib/lua_fuzzy.lua +++ b/lualib/lua_fuzzy.lua @@ -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 diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index ae959c34e..459a78e69 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -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; } -- 2.39.5