]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Use proper hashing when getting texts fuzzy hash
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 4 Jul 2018 13:56:47 +0000 (14:56 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 4 Jul 2018 14:54:39 +0000 (15:54 +0100)
lualib/rspamadm/mime.lua
src/lua/lua_mimepart.c

index f31fe29f1a5a4b99c9b44abd05603e20a1e9cadf..f41529646ea5e9e5244561be9a505234fdb24f0d 100644 (file)
@@ -325,12 +325,22 @@ local function stat_handler(opts)
       end
       for _,part in ipairs(parts) do
         if not part:is_multipart() then
-          table.insert(out_elts[fname], {
-            digest = part:get_digest(),
-            file = part:get_filename(),
-            type = string.format('%s/%s', part:get_type())
-          })
-
+          local text = part:get_text()
+
+          if text then
+            local digest,shingles = text:get_fuzzy_hashes(task:get_mempool())
+            table.insert(out_elts[fname], {
+              digest = digest,
+              shingles = rspamd_logger.slog('%s', shingles),
+              type = string.format('%s/%s', part:get_type())
+            })
+          else
+            table.insert(out_elts[fname], {
+              digest = part:get_digest(),
+              file = part:get_filename(),
+              type = string.format('%s/%s', part:get_type())
+            })
+          end
         end
       end
     end
index 822df2f36f10efe7b744b99eee7b0d4c79438a4a..dd4e998a1c6ab29bbfb1176cc15faccaaa41c5a7 100644 (file)
@@ -906,6 +906,8 @@ lua_textpart_get_fuzzy_hashes (lua_State * L)
                /* TODO: add short text support */
 
                /* Calculate direct hash */
+               rspamd_cryptobox_hash_init (&st, key, rspamd_cryptobox_HASHKEYBYTES);
+
                for (i = 0; i < part->normalized_words->len; i ++) {
                        word = &g_array_index (part->normalized_words, rspamd_stat_token_t, i);
                        rspamd_cryptobox_hash_update (&st, word->begin, word->len);
@@ -915,7 +917,7 @@ lua_textpart_get_fuzzy_hashes (lua_State * L)
 
                rspamd_encode_hex_buf (digest, sizeof (digest), hexdigest,
                                sizeof (hexdigest));
-               lua_pushstring (L, hexdigest);
+               lua_pushlstring (L, hexdigest, sizeof (hexdigest) - 1);
 
                sgl = rspamd_shingles_from_text (part->normalized_words, key,
                                pool, lua_shingles_filter, part, RSPAMD_SHINGLES_MUMHASH);