Skip to content

Commit

Permalink
Sanitize trailer dictionary after reading malformed file
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwhitington committed Jul 18, 2019
1 parent 36dd7f1 commit bb4efff
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pdfread.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1772,14 +1772,27 @@ let read_malformed_pdf upw opw i =
raise (Pdf.PDFError (Pdf.input_pdferror i "Malformed /Root entry"))
in
i.Pdfio.seek_in 0;
(* Fix Size entry and remove Prev, XRefStm, Filter, Index, W, Type,
and DecodeParms *)
let trailerdict' =
Pdf.Dictionary
(add "/Size" (Pdf.Integer (length objects))
(remove "/W"
(remove "/Type"
(remove "/Index"
(remove "/Prev"
(remove "/XRefStm"
(remove "/Filter"
(remove "/DecodeParms" trailerdict))))))))
in
let was_linearized = is_linearized i in
Printf.eprintf "Malformed PDF reconstruction succeeded!\n";
flush stderr;
{Pdf.major = major;
Pdf.minor = minor;
Pdf.root = root;
Pdf.objects = Pdf.objects_of_list None objects;
Pdf.trailerdict = Pdf.Dictionary trailerdict;
Pdf.trailerdict = trailerdict';
Pdf.was_linearized = was_linearized;
Pdf.saved_encryption = None}

Expand Down

0 comments on commit bb4efff

Please sign in to comment.