From f996f2fc9399b84779c187fac00e097977db53e9 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Fri, 20 Nov 2026 22:29:14 +0100 Subject: [PATCH] engine: file.print.page asks no printer driver while printing is disabled The panic hunt turns printing off so no command reaches a printer, but file.print.page still asked the Windows driver for the default printer's page. On a Windows runner that call hung while holding SPOOLER, so file.printers, file.printOneCopy and file.package timed out behind it and main went red (run 44791314463). It now refuses, after checking its own parameters, when disable_printing or PHOTOCRAFT_NO_PRINT is set. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/print_cmds.rs | 16 ++++++++++++---- crates/engine/src/cmd/print_cmds/tests.rs | 6 ++++++ crates/engine/tests/panic_hunt.rs | 3 ++- docs/development.md | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/crates/engine/src/cmd/print_cmds.rs b/crates/engine/src/cmd/print_cmds.rs index 8091a10f99..3007c0f649 100644 --- a/crates/engine/src/cmd/print_cmds.rs +++ b/crates/engine/src/cmd/print_cmds.rs @@ -1433,8 +1433,13 @@ fn printer_page(_: &mut Session, p: &Value) -> Result { _ => return Err(bad("file.print.page", "orientation is \"portrait\" or \"landscape\"")), }, }; - let printer = printer_name(p)?; let mut settings = printer_settings(p)?; + // A driver query is still a call into a printer driver, which can hang (and holds SPOOLER + // while it does), so a process that turned printing off asks no driver here either. + if printing_disabled() { + return Err(other("printing is disabled in this process (disable_printing or PHOTOCRAFT_NO_PRINT); file.print.page asks no printer driver")); + } + let printer = printer_name(p)?; if let Some(landscape) = landscape { let base = match settings { Some(s) => s, @@ -1451,11 +1456,14 @@ fn printer_page(_: &mut Session, p: &Value) -> Result { Ok(out) } -/// Set once by test harnesses (the panic hunt) so no command in the process can reach a printer. +/// Set once by test harnesses (the panic hunt) so no command in the process can reach a printer +/// or its driver: `file.print` and `file.printOneCopy` refuse to spool, and `file.print.page` +/// refuses to ask a driver for its page. static PRINTING_DISABLED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); -/// Refuse to spool anything from this process from now on (tests, fuzzing). The -/// `PHOTOCRAFT_NO_PRINT` environment variable does the same for a whole shell (CI). +/// Refuse to spool anything, or ask a printer driver for its page, from this process from now on +/// (tests, fuzzing). The `PHOTOCRAFT_NO_PRINT` environment variable does the same for a whole +/// shell (CI). pub fn disable_printing() { PRINTING_DISABLED.store(true, std::sync::atomic::Ordering::Relaxed); } diff --git a/crates/engine/src/cmd/print_cmds/tests.rs b/crates/engine/src/cmd/print_cmds/tests.rs index 8136cd2fba..c704691ecc 100644 --- a/crates/engine/src/cmd/print_cmds/tests.rs +++ b/crates/engine/src/cmd/print_cmds/tests.rs @@ -783,6 +783,12 @@ fn disabled_printing_never_spools() { let e = s.execute("file.print", json!({})).unwrap_err().to_string(); assert!(e.contains("printing is disabled"), "{e}"); assert!(s.execute("file.printOneCopy", json!({})).is_err()); + // Nor does it ask a driver for its page: on a Windows runner that call can hang, holding SPOOLER. + let e = s.execute("file.print.page", json!({})).unwrap_err().to_string(); + assert!(e.contains("printing is disabled"), "{e}"); + // Bad values are still the error they were, before the check. + let e = s.execute("file.print.page", json!({"orientation": "sideways"})).unwrap_err().to_string(); + assert!(e.contains("orientation"), "{e}"); // A dry run still renders and reports the command it would have run. let r = s.execute("file.print", json!({"dryRun": true})).unwrap(); assert_eq!(r["sent"], false); diff --git a/crates/engine/tests/panic_hunt.rs b/crates/engine/tests/panic_hunt.rs index 81f893ee68..acb260b918 100644 --- a/crates/engine/tests/panic_hunt.rs +++ b/crates/engine/tests/panic_hunt.rs @@ -10,7 +10,8 @@ use std::sync::{Mutex, Once, PoisonError, mpsc}; use std::time::Duration; fn fresh() -> Session { - // Belt and braces with the EXTERNAL skip below: nothing in this process may reach a printer. + // Belt and braces with CI's PHOTOCRAFT_NO_PRINT: nothing in this process may reach a printer + // or its driver (file.print.page refuses to ask one, so a hung driver can't hold SPOOLER). photocraft_engine::print_cmds::disable_printing(); let mut s = Session::new(); // `file.printers` and `file.print.printers` list no printers and do not ask the spooler. diff --git a/docs/development.md b/docs/development.md index bd62ca10e1..b1e00f38e7 100644 --- a/docs/development.md +++ b/docs/development.md @@ -191,7 +191,7 @@ A file dragged in from the desktop logs two lines at `info` (`file_open.rs`; fil |---|---| | `PHOTOCRAFT_GPU=1` (or `=0`) | Headless CLI: prefer GPU composition and flat export (0 to disable, empty to unset). Explicit `--gpu`/`--no-gpu` CLI flags override this variable. `file.export.quickExport` composites and encodes inside the engine, which has no renderer, so it always runs on the CPU; `run --gpu` prints a one-time warning when a step uses it | | `PHOTOCRAFT_CONTROL_PORT` | Same as `--control `; also the port for `photocraft-cli serve --port` and `mcp --bridge` when the flag is absent. Empty is unset | -| `PHOTOCRAFT_NO_PRINT` | Set to anything but `0`: `file.print` / `file.printOneCopy` refuse to spool (`dryRun` still works). CI sets it, with `LPDEST=photocraft-no-such-printer` as a second net; set both when running the panic hunt or fuzzers locally | +| `PHOTOCRAFT_NO_PRINT` | Set to anything but `0`: `file.print` / `file.printOneCopy` refuse to spool (`dryRun` still works) and `file.print.page` asks no printer driver. CI sets it, with `LPDEST=photocraft-no-such-printer` as a second net; set both when running the panic hunt or fuzzers locally | | `RUST_LOG` | Log levels for standard error and the log file (see [Logs](#logs)) | | `PHOTOCRAFT_CONTROL_TOKEN` | 64-hex bearer token for control TCP (avoid on shared systems where environment inspection is possible) | | `PHOTOCRAFT_CONTROL_TOKEN_FILE` | Read, or create for a server, the control bearer-token file |