From 5490e9c3f999d648155c75e3821ab6cd23e3ef76 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:35:02 +0100 Subject: [PATCH 1/3] fix(automation): reject invalid doc.render parameters before rendering Validate the parameter object and optional output path before rendering. Keep the existing behavior for an omitted or null path and string output paths. --- crates/automation/src/rpc.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/automation/src/rpc.rs b/crates/automation/src/rpc.rs index 404891f61e..a0a62ebd82 100644 --- a/crates/automation/src/rpc.rs +++ b/crates/automation/src/rpc.rs @@ -223,6 +223,15 @@ impl Headless { } "doc.inspect" => self.inspect(index_of(&p)?), "doc.render" => { + // Invalid file requests must not fall back to a base64 response. + if !p.is_object() { + return Err(bad("doc.render params must be an object")); + } + let path = match p.get("path") { + None | Some(Value::Null) => None, + Some(Value::String(path)) => Some(path.as_str()), + Some(_) => return Err(bad("`path` must be a string")), + }; let max = match p.get("maxSide") { None => 1024, Some(value) => { @@ -232,7 +241,7 @@ impl Headless { let png = self.render_png(index_of(&p)?, max)?; // A GPU to CPU fallback is reported with this reply, not on the next save. let warnings = self.drain_diagnostics(); - let mut reply = match str_of(&p, "path") { + let mut reply = match path { Some(path) => { self.write_render(&PathBuf::from(path), &png)?; json!({"path": path, "bytes": png.len()}) From 84c9cbb3a09ff00ac844f30fffe0c4366421a747 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:35:41 +0100 Subject: [PATCH 2/3] test(automation): cover malformed doc.render requests Check rejection for invalid parameter containers and path types. Verify that omitted and null paths still return an inline PNG. --- crates/automation/src/rpc/tests.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/automation/src/rpc/tests.rs b/crates/automation/src/rpc/tests.rs index 51f053b595..d2dc3e0fc7 100644 --- a/crates/automation/src/rpc/tests.rs +++ b/crates/automation/src/rpc/tests.rs @@ -176,6 +176,32 @@ fn batch_rejects_too_many_steps() { assert!(error.to_string().contains("maximum is 256")); } +#[test] +fn render_rejects_malformed_requests_and_keeps_missing_or_null_path_behavior() { + let h = session(); + let mut g = h.lock().unwrap(); + g.handle("doc.new", json!({"width": 8, "height": 8})).unwrap(); + let before = g.inspect(None).unwrap(); + for params in [json!([]), json!([0]), json!(123), json!(false), json!("out.png")] { + let error = g.handle("doc.render", params.clone()).unwrap_err(); + assert!(matches!(&error, AutomationError::BadRequest(_)), "{params}: {error}"); + assert!(error.to_string().contains("doc.render params must be an object"), "{params}: {error}"); + assert_eq!(g.inspect(None).unwrap(), before, "invalid params {params} changed the document"); + } + for path in [json!(123), json!(false), json!([]), json!({})] { + let error = g.handle("doc.render", json!({"path": path})).unwrap_err(); + assert!(matches!(&error, AutomationError::BadRequest(_)), "{path}: {error}"); + assert!(error.to_string().contains("`path` must be a string"), "{path}: {error}"); + assert_eq!(g.inspect(None).unwrap(), before, "invalid path {path} changed the document"); + } + for params in [Value::Null, json!({}), json!({"path": null})] { + let reply = g.handle("doc.render", params.clone()).unwrap(); + assert_eq!(reply["mime"], "image/png", "{params}: {reply}"); + let png = base64::engine::general_purpose::STANDARD.decode(reply["base64"].as_str().unwrap()).unwrap(); + assert_eq!(photocraft_codecs::decode(&png).unwrap().dimensions(), (8, 8)); + } +} + #[test] fn render_to_file_and_base64() { let h = session(); From 9b67220c927d3656b29a0d626219fb4bf86737b8 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:50:11 +0100 Subject: [PATCH 3/3] docs(automation): clarify null params for doc.render Document the tested shorthand for an empty request and the distinction between inline PNG and string output paths. --- docs/control-protocol.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 22225621a7..ff18862c2d 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -571,6 +571,10 @@ An `index` targets that one call: `doc.place`, `doc.exportLayers`, `doc.exportDa without making it the active one, so the next call without `index` still runs on the document that was active before (`doc.select` is the method that changes it). +`doc.render` treats omitted `params` and `"params": null` as `{}`. Pass a string `path` +for a file reply. An omitted or null `path` requests an inline PNG. Other parameter +container or path types return an error before rendering. + ```sh printf '%s\n' \ '{"id":1,"method":"doc.open","params":{"path":"in.jpg"}}' \