Fix for -gs-malformed on files with wrong owner or user password

This commit is contained in:
John Whitington 2019-08-18 10:55:40 +01:00
parent c610e3e8d7
commit e6b3cc8a65
3 changed files with 15 additions and 6 deletions

View File

@ -1677,6 +1677,10 @@ let setdraftremoveonly s =
let setgsquiet () = let setgsquiet () =
args.gs_quiet <- true args.gs_quiet <- true
let whingemalformed () =
prerr_string "Command line must be of exactly the form\ncpdf <infile> -gs <path> -gs-malformed-force -o <outfile>\n";
exit 1
(* Parse a control file, make an argv, and then make Arg parse it. *) (* Parse a control file, make an argv, and then make Arg parse it. *)
let rec make_control_argv_and_parse filename = let rec make_control_argv_and_parse filename =
control_args := !control_args @ parse_control_file filename control_args := !control_args @ parse_control_file filename
@ -2291,7 +2295,9 @@ and specs =
("-gs-quiet", Arg.Unit setgsquiet, " Make gs go into quiet mode"); ("-gs-quiet", Arg.Unit setgsquiet, " Make gs go into quiet mode");
("-squeeze", Arg.Unit setsqueeze, " Squeeze"); ("-squeeze", Arg.Unit setsqueeze, " Squeeze");
("-squeeze-log-to", Arg.String setsqueezelogto, " Squeeze log location"); ("-squeeze-log-to", Arg.String setsqueezelogto, " Squeeze log location");
(*These items are undocumented *) (* Just for error reporting *)
("-gs-malformed-force", Arg.Unit whingemalformed, "");
(* These items are undocumented *)
("-remove-unused-resources", Arg.Unit (setop RemoveUnusedResources), ""); ("-remove-unused-resources", Arg.Unit (setop RemoveUnusedResources), "");
("-stay-on-error", Arg.Unit setstayonerror, ""); ("-stay-on-error", Arg.Unit setstayonerror, "");
("-extract-fontfile", Arg.Unit (setop ExtractFontFile), ""); ("-extract-fontfile", Arg.Unit (setop ExtractFontFile), "");
@ -2405,7 +2411,7 @@ let rec get_single_pdf ?(decrypt=true) ?(fail=false) op read_lazy =
end end
| _ -> () | _ -> ()
end; end;
Printf.eprintf "Failed to read malformed PDF file. Consider using -gs-malformed\n"; Printf.eprintf "get_single_pdf: failed to read malformed PDF file. Consider using -gs-malformed\n";
exit 2 exit 2
in in
match args.inputs with match args.inputs with
@ -2419,7 +2425,8 @@ let rec get_single_pdf ?(decrypt=true) ?(fail=false) op read_lazy =
else else
pdfread_pdf_of_file ?revision (optstring u) (optstring o) inname pdfread_pdf_of_file ?revision (optstring u) (optstring o) inname
with with
_ -> | Cpdf.SoftError _ as e -> raise e (* Bad owner or user password *)
| _ ->
if args.gs_malformed then if args.gs_malformed then
begin begin
failout (); failout ();
@ -2487,7 +2494,7 @@ let rec get_pdf_from_input_kind ?(read_lazy=false) ?(decrypt=true) ?(fail=false)
end end
| _ -> () | _ -> ()
end; end;
Printf.eprintf "Failed to read malformed PDF file. Consider using -gs-malformed\n"; Printf.eprintf "get_pdf_from_input_kind: failed to read malformed PDF file. Consider using -gs-malformed\n";
exit 2 exit 2
in in
match ik with match ik with
@ -2512,7 +2519,9 @@ let rec get_pdf_from_input_kind ?(read_lazy=false) ?(decrypt=true) ?(fail=false)
else else
pdfread_pdf_of_file ?revision (optstring u) (optstring o) s pdfread_pdf_of_file ?revision (optstring u) (optstring o) s
with with
_ -> | Cpdf.SoftError _ as e -> raise e (* Bad owner or user password *)
| e ->
Printf.printf "%s\n" (Printexc.to_string e);
if args.gs_malformed then if args.gs_malformed then
begin begin
failout (); failout ();

Binary file not shown.

View File

@ -1237,7 +1237,7 @@ tree with no entry being more than one greater than the last).
As an alternative to extracting a bookmark file and manipulating the open-status of bookmarks, mass manipulation may be achieved by the following operation: As an alternative to extracting a bookmark file and manipulating the open-status of bookmarks, mass manipulation may be achieved by the following operation:
\begin{framed} \begin{framed}
\small\verb!cpdf -open-bookmarks-to-level <level> in.pdf -o out.pdf! \small\verb!cpdf -bookmarks-open-to-level <level> in.pdf -o out.pdf!
\end{framed} \end{framed}
\noindent A level of 0 will close all bookmarks, level 1 will open just the top level, closing all others etc. To open all of them, pick a sufficiently large level. \noindent A level of 0 will close all bookmarks, level 1 will open just the top level, closing all others etc. To open all of them, pick a sufficiently large level.