Fix -add-rectangle when PMAXX ect.

This commit is contained in:
John Whitington
2025-05-29 18:47:13 +01:00
parent 6fccb20605
commit 1e07967755
6 changed files with 13 additions and 5 deletions

View File

@@ -13,6 +13,7 @@ o New -decompress-just-content for easier content stream debugging
Fixes: Fixes:
* Sanitizes inputs to prevent command injection attacks * Sanitizes inputs to prevent command injection attacks
o Fix PMAXX et al. w.r.t -add-rectangle
* = Supported by a grant from NLnet * = Supported by a grant from NLnet

View File

@@ -579,7 +579,7 @@ let
!pdf !pdf
let addrectangle let addrectangle
fast (w, h) colour outline linewidth opacity position relative_to_cropbox fast coord colour outline linewidth opacity position relative_to_cropbox
underneath range pdf underneath range pdf
= =
let addrectangle_page _ page = let addrectangle_page _ page =
@@ -607,6 +607,11 @@ let addrectangle
else else
Pdf.parse_rectangle pdf page.Pdfpage.mediabox Pdf.parse_rectangle pdf page.Pdfpage.mediabox
in in
let w, h =
match Cpdfcoord.parse_units_string pdf page coord with
| [w; h] -> w, h
| _ -> error "bad coordinate specification"
in
let x, y, _ = let x, y, _ =
Cpdfposition.calculate_position false w mediabox position Cpdfposition.calculate_position false w mediabox position
in in

View File

@@ -48,10 +48,10 @@ val addtexts :
Pdf.t ->(*pdf*) Pdf.t ->(*pdf*)
Pdf.t Pdf.t
(** Add a rectangle to the given pages. [addrectangle fast (w, h) colour outline linewidth opacity position relative_to_cropbox underneath range pdf]. *) (** Add a rectangle to the given pages. [addrectangle fast coordinate colour outline linewidth opacity position relative_to_cropbox underneath range pdf]. *)
val addrectangle : val addrectangle :
bool -> bool ->
float * float -> string ->
colour -> colour ->
bool -> bool ->
float -> float ->

View File

@@ -4590,7 +4590,7 @@ let go () =
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
write_pdf false write_pdf false
(Cpdfaddtext.addrectangle (Cpdfaddtext.addrectangle
args.fast (Cpdfcoord.parse_coordinate pdf args.coord) args.fast args.coord
args.color args.outline args.linewidth args.opacity args.position args.color args.outline args.linewidth args.opacity args.position
args.relative_to_cropbox args.underneath range pdf) args.relative_to_cropbox args.underneath range pdf)
| Some (AddBookmarks file) -> | Some (AddBookmarks file) ->

View File

@@ -14,5 +14,7 @@ val parse_coordinate : Pdf.t -> string -> float * float
(** Read a list of coordinates from a string *) (** Read a list of coordinates from a string *)
val parse_coordinates : Pdf.t -> string -> (float * float) list val parse_coordinates : Pdf.t -> string -> (float * float) list
val parse_units_string : Pdf.t -> Pdfpage.t -> string -> float list
(** Read a single number from a string *) (** Read a single number from a string *)
val parse_single_number : Pdf.t -> string -> float val parse_single_number : Pdf.t -> string -> float

View File

@@ -188,7 +188,7 @@ let add_border linewidth ~fast pdf =
let firstpage = hd (Pdfpage.pages_of_pagetree pdf) in let firstpage = hd (Pdfpage.pages_of_pagetree pdf) in
let _, _, w, h = Pdf.parse_rectangle pdf firstpage.Pdfpage.mediabox in let _, _, w, h = Pdf.parse_rectangle pdf firstpage.Pdfpage.mediabox in
Cpdfaddtext.addrectangle Cpdfaddtext.addrectangle
fast (w -. linewidth, h -. linewidth) (RGB (0., 0., 0.)) true linewidth 1. (Cpdfposition.BottomLeft (linewidth /. 2., linewidth /. 2.)) fast (string_of_float (w -. linewidth) ^ " " ^ string_of_float (h -. linewidth)) (RGB (0., 0., 0.)) true linewidth 1. (Cpdfposition.BottomLeft (linewidth /. 2., linewidth /. 2.))
false false (ilist 1 (Pdfpage.endpage pdf)) pdf false false (ilist 1 (Pdfpage.endpage pdf)) pdf
let impose ~process_struct_tree ~x ~y ~fit ~columns ~rtl ~btt ~center ~margin ~spacing ~linewidth ~fast pdf = let impose ~process_struct_tree ~x ~y ~fit ~columns ~rtl ~btt ~center ~margin ~spacing ~linewidth ~fast pdf =