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 <[email protected]>
This commit is contained in:
FredAppsandClaude Opus 5.5 committed 2026-11-20 22:29:14 +01:00
1 parent 877d588440
commit f996f2fc93
4 files changed
+21 -6

No files matched your search

+12 -4
View File
@@ -1433,8 +1433,13 @@ fn printer_page(_: &mut Session, p: &Value) -> Result<Value> {
_ => 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<Value> {
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);
}
@@ -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);
+2 -1
View File
@@ -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.
+1 -1
View File
@@ -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 <port>`; 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 |