From fe8df9944b2132bbb421b0291852e32b7dfdcf92 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 13 Apr 2020 15:16:15 +0100 Subject: [Minor] Lua_content: Process xref objects and detect encryption there --- lualib/lua_content/pdf.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lualib/lua_content/pdf.lua b/lualib/lua_content/pdf.lua index c69c9e3d2..b410c2a14 100644 --- a/lualib/lua_content/pdf.lua +++ b/lualib/lua_content/pdf.lua @@ -408,6 +408,10 @@ end -- Conditionally extract stream data from object and attach it as obj.uncompressed local function maybe_extract_object_stream(obj, pdf, task) + if pdf.encrypted then + -- TODO add decryption some day + return nil + end local dict = obj.dict if dict.Length then local len = math.min(obj.stream.len, @@ -607,6 +611,17 @@ local function process_catalog(task, pdf, obj) end end +local function process_xref(task, pdf, obj) + if obj.dict then + if obj.dict.Encrypt then + local encrypt = maybe_dereference_object(obj.dict.Encrypt, pdf, task) + lua_util.debugm(N, task, 'found encrypt: %s in xref object %s:%s', + encrypt, obj.major, obj.minor) + pdf.encrypted = true + end + end +end + process_dict = function(task, pdf, obj, dict) if not obj.type and type(dict) == 'table' then if dict.Type and type(dict.Type) == 'string' then @@ -705,6 +720,9 @@ process_dict = function(task, pdf, obj, dict) process_action(task, pdf, obj) elseif obj.type == 'Catalog' then process_catalog(task, pdf, obj) + elseif obj.type == 'XRef' then + -- XRef stream instead of trailer from PDF 1.5 (thanks Adobe) + process_xref(task, pdf, obj) elseif obj.type == 'Javascript' then local js = maybe_dereference_object(obj.dict.JS, pdf, task) -- cgit v1.2.3