From: Vsevolod Stakhov Date: Thu, 25 Sep 2025 08:31:08 +0000 (+0100) Subject: [Fix] Fix empty input in lua_magic X-Git-Tag: 3.13.1~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=55e3498a8b639e0983935a2ded98770170a72f96;p=thirdparty%2Frspamd.git [Fix] Fix empty input in lua_magic Issue: #5633 --- diff --git a/lualib/lua_magic/init.lua b/lualib/lua_magic/init.lua index cef1ddcea8..715358f804 100644 --- a/lualib/lua_magic/init.lua +++ b/lualib/lua_magic/init.lua @@ -306,6 +306,10 @@ exports.detect = function(part, log_obj) if type(input) == 'userdata' then local inplen = #input + if inplen == 0 then + -- Empty input: nothing to match + return nil + end -- Check tail matches if inplen > min_tail_offset then @@ -315,9 +319,11 @@ exports.detect = function(part, log_obj) end -- Try short match - local head = input:span(1, math.min(max_short_offset, inplen)) - match_chunk(head, input, inplen, 0, - compiled_short_patterns, short_patterns, log_obj, res, part) + if max_short_offset > 0 then + local head = input:span(1, math.min(max_short_offset, inplen)) + match_chunk(head, input, inplen, 0, + compiled_short_patterns, short_patterns, log_obj, res, part) + end -- Check if we have enough data or go to long patterns local extensions, confidence = process_detected(res)