Proof Setup: a setup that would be too large to load is not saved

view.proofSetup.save refuses a setup whose file would be larger than
the 64 KiB view.proofSetup.load reads (a device profile with a very
long name), and writes nothing.
This commit is contained in:
dotCooCoo committed 2026-11-19 05:39:51 -08:00
1 parent 5d8609e881
commit efe4c7e30f
2 files changed
+15 -2

No files matched your search

@@ -159,6 +159,11 @@ pub(super) fn save(s: &mut Session, p: &Value) -> Result<Value> {
let mut setup = proof::view().setup;
setup_params(p, &mut setup, C)?;
check_device(&setup.target).map_err(|e| bad(C, e))?;
// A file `view.proofSetup.load` would refuse is not written (a device with a very long name).
let bytes = encode(&setup);
if bytes.len() > MAX_FILE {
return Err(bad(C, format!("{path}: larger than {MAX_FILE} bytes")));
}
if named
&& let Some(dir) = std::path::Path::new(&path).parent()
&& !dir.is_dir()
@@ -166,7 +171,7 @@ pub(super) fn save(s: &mut Session, p: &Value) -> Result<Value> {
crate::file_access::check_write(&path).map_err(EngineError::Other)?;
std::fs::create_dir_all(dir).map_err(|e| bad(C, format!("{}: {e}", dir.display())))?;
}
fileio::write_file(&path, &encode(&setup))?;
fileio::write_file(&path, &bytes)?;
s.proof_setup_saves += 1;
let mut r = setup_json(&setup);
r.insert("path".into(), json!(path));
+9 -1
View File
@@ -767,7 +767,8 @@ fn a_saved_proof_setup_loads_back() {
assert_eq!(vectorcraft_render::proof::view().setup, ProofSetup { simulate_paper: true, ..want });
}
/// Saving refuses a target that is not a device, bad params and a bad name; loading refuses a file
/// Saving refuses a target that is not a device, bad params, a bad name and a file larger than
/// loading reads; loading refuses a file
/// that is too large, not a proof setup, newer, or whose device is a profile that is not loaded,
/// and the proof view stays as it was.
#[test]
@@ -791,6 +792,13 @@ fn proof_setup_files_refuse_what_they_cannot_use() {
refused(&mut s, "view.proofSetup.save", json!({"name": bad_name}), "`name`");
}
refused(&mut s, "view.proofSetup.save", json!({"name": "x".repeat(101)}), "longer than 100 characters");
// A device whose name makes the file larger than load reads is refused, and nothing is written.
let long = "Long Profile Name ".repeat(4000);
cms::register_icc(&cms::icc_bytes(cms::DISPLAY_P3).unwrap(), Some(long.clone())).unwrap();
let refusal = s.execute("view.proofSetup.save", &json!({"path": path, "target": format!("rgb:{long}")}));
cms::unregister_icc(&long);
assert!(refusal.unwrap_err().to_string().contains("larger than 65536 bytes"), "a setup load can't read is refused");
assert!(!std::path::Path::new(&path).exists(), "nothing is written");
let before = vectorcraft_render::proof::view();
let write = |n: &str, text: &str| {
let p = file(n);