aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-04 14:56:47 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-04 15:54:39 +0100
commit5d3677f48bf7b0493bab5cae6f7928f9a878f320 (patch)
treed3c028311c7e65079ee819510790bba24d29f45d
parent2bf955712401df23751afdb5196b42ffa5fd6694 (diff)
downloadrspamd-5d3677f48bf7b0493bab5cae6f7928f9a878f320.tar.gz
rspamd-5d3677f48bf7b0493bab5cae6f7928f9a878f320.zip
[Minor] Use proper hashing when getting texts fuzzy hash
-rw-r--r--lualib/rspamadm/mime.lua22
-rw-r--r--src/lua/lua_mimepart.c4
2 files changed, 19 insertions, 7 deletions
diff --git a/lualib/rspamadm/mime.lua b/lualib/rspamadm/mime.lua
index f31fe29f1..f41529646 100644
--- a/lualib/rspamadm/mime.lua
+++ b/lualib/rspamadm/mime.lua
@@ -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
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index 822df2f36..dd4e998a1 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -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);