]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix empty input in lua_magic
authorVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 25 Sep 2025 08:31:08 +0000 (09:31 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 25 Sep 2025 08:31:08 +0000 (09:31 +0100)
Issue: #5633

lualib/lua_magic/init.lua

index cef1ddcea8d3db75eb1c4722b36a478385cbc7cc..715358f804e4b70217f2f2a7d9d586e9f11f6dbd 100644 (file)
@@ -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)