PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
Merge PR #3997: fix(automation): guard MCP dispatch and bound line and file reads (#3924)
aiongg19b36de16f08
diff --cc crates/automation/src/comments.rsindex 3d1b8d82d,1266db010..35d8a6282--- a/crates/automation/src/comments.rs+++ b/crates/automation/src/comments.rs@@@ -680,30 -678,15 +680,30 @@@ impl Automationpub(crate) fn stamp_custom(&mut self, a: &Args) -> Result<Value> {let page = self.page(a)?;let info = self.doc(a)?.info.pages[page].clone();+ let rect = match (a.nums::<4>("rect")?, a.get("at")) {+ (Some(_), Some(_)) => return Err(ToolError::InvalidArgs("pass at (a point) or rect (a box), not both".into())),+ (Some(r), None) => {+ let (w, h) = ((r[2] - r[0]).abs(), (r[3] - r[1]).abs());+ if !((1.0..=MAX_STAMP_SIDE).contains(&w) && (1.0..=MAX_STAMP_SIDE).contains(&h)) {+ return Err(ToolError::InvalidArgs(format!(+ "rect must be [x0, y0, x1, y1] with each side at least 1 pt and at most {MAX_STAMP_SIDE} pt"+ )));+ }+ rect_to_user(&info, r)+ }+ (None, _) => {+ let [x, y] = a.need::<2>("at", "a stamp (its centre, or pass rect)")?;+ let [ux, uy] = to_user(&info, x, y);+ [ux, uy, ux, uy]+ }+ };let path = self.resolve(a.str("path")?, false)?;- let bytes = std::fs::read(&path).map_err(|e| failed(format!("{}: {e}", path.display())))?;+ let bytes = crate::read_input(&path)?;let file = path.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default();let name = a.opt_str("name")?.map(str::to_owned).unwrap_or_else(|| file.rsplit_once('.').map_or(file.clone(), |(s, _)| s.to_owned()));- let [x, y] = a.need::<2>("at", "a stamp (its centre)")?;- let [ux, uy] = to_user(&info, x, y);let edit = Edit::AddCustomStamp {page,- rect: [ux, uy, ux, uy],+ rect,name,file: pdfcraft_engine::MarkFile {name: file,