commit 207e95f: [Minor] Add small sanity check to avoid extensive computations

Vsevolod Stakhov vsevolod at highsecure.ru
Thu May 21 16:28:06 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-05-21 17:26:47 +0100
URL: https://github.com/rspamd/rspamd/commit/207e95fe7b6dcac15a00995c13a86bb748a2dcf4 (HEAD -> master)

[Minor] Add small sanity check to avoid extensive computations

---
 lualib/lua_content/pdf.lua | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lualib/lua_content/pdf.lua b/lualib/lua_content/pdf.lua
index 0e3f024ae..fb3d07a93 100644
--- a/lualib/lua_content/pdf.lua
+++ b/lualib/lua_content/pdf.lua
@@ -838,6 +838,10 @@ end
 local function extract_outer_objects(task, input, pdf)
   local start_pos, end_pos = 1, 1
   local obj_count = 0
+
+  lua_util.debugm(N, task, "pdf: extract objects from %s start positions and %s end positions",
+      #pdf.start_objects, #pdf.end_objects)
+
   while start_pos <= #pdf.start_objects and end_pos <= #pdf.end_objects do
     local first = pdf.start_objects[start_pos]
     local last = pdf.end_objects[end_pos]
@@ -1181,12 +1185,23 @@ end
 processors.trailer = function(input, task, positions, output)
   local last_pos = positions[#positions]
 
+  lua_util.debugm(N, task, 'pdf: process trailer at position %s (%s total length)',
+      last_pos, #input)
+
   local last_span = input:span(last_pos[1])
+  local lines_checked = 0
   for line in last_span:lines(true) do
     if line:find('/Encrypt ') then
       lua_util.debugm(N, task, "pdf: found encrypted line in trailer: %s",
           line)
       output.encrypted = true
+      break
+    end
+    lines_checked = lines_checked + 1
+
+    if lines_checked > 100 then
+      lua_util.debugm(N, task, "pdf: trailer has too many lines, stop checking")
+      break
     end
   end
 end


More information about the Commits mailing list