From 389c63aa5171ae87e599a6cb326ce94a8d645bbb Mon Sep 17 00:00:00 2001 From: John Whitington Date: Thu, 6 Jun 2024 16:53:29 +0100 Subject: [PATCH] Embedded file check --- cpdfua.ml | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/cpdfua.ml b/cpdfua.ml index 74ea31e..b6877c7 100644 --- a/cpdfua.ml +++ b/cpdfua.ml @@ -109,7 +109,38 @@ let matterhorn_20_003 pdf = () (* The file specification dictionary for an embedded file does not contain F and UF entries. *) -let matterhorn_21_001 pdf = () +let matterhorn_21_001 pdf = + let from_nametree = + match Pdf.lookup_direct pdf "/Root" pdf.Pdf.trailerdict with + | Some catalog -> + begin match Pdf.lookup_direct pdf "/Names" catalog with + | Some names -> + begin match Pdf.lookup_direct pdf "/EmbeddedFiles" names with + | Some embeddedfiles -> + map snd (Pdf.contents_of_nametree pdf embeddedfiles) + | None -> [] + end + | None -> [] + end + | None -> [] + in + let from_annots = + option_map + (fun x -> + if x.Pdfannot.subtype = Pdfannot.FileAttachment + then Pdf.lookup_direct pdf "/FS" x.Pdfannot.annotrest + else None) + (flatten (map (Pdfannot.annotations_of_page pdf) (Pdfpage.pages_of_pagetree pdf))) + in + if + List.exists + (fun x -> + match Pdf.lookup_direct pdf "/F" x, Pdf.lookup_direct pdf "/UF" x with + | Some _, Some _ -> false + | _ -> true) + (from_nametree @ from_annots) + then + merror () (* File contains the dynamicRender element with value “required”. *) let matterhorn_25_001 pdf =