From efccb678d8f32a80f4553a7fcc4f3a40aee6a40f Mon Sep 17 00:00:00 2001 From: yoriswind Date: Sun, 1 Nov 2026 17:39:05 -0800 Subject: [PATCH] Fix Batch regression compilation and document admission boundaries --- crates/algo/src/blur2/shape_tests.rs | 3 +++ crates/engine/src/cmd/atn_cmds/steps_batch.rs | 6 ++++++ crates/engine/src/cmd/atn_cmds/steps_lookup.rs | 3 +++ crates/engine/src/cmd/atn_cmds/steps_shape_blur.rs | 2 ++ crates/engine/src/cmd/atn_cmds/tests.rs | 4 ++++ crates/engine/src/cmd/file_cmds/batch_naming.rs | 10 ++++++++-- crates/engine/src/cmd/file_cmds/batch_run.rs | 2 ++ crates/engine/src/cmd/file_cmds/tests.rs | 8 +++++--- crates/engine/tests/it/atn_color_lookup.rs | 6 ++++++ crates/engine/tests/it/atn_dialog_filters.rs | 3 +++ crates/engine/tests/it/atn_shape_blur.rs | 7 +++++++ crates/psd/src/csh.rs | 1 + 12 files changed, 50 insertions(+), 5 deletions(-) diff --git a/crates/algo/src/blur2/shape_tests.rs b/crates/algo/src/blur2/shape_tests.rs index fcba4ab66ff..6ca6e8dfc5b 100644 --- a/crates/algo/src/blur2/shape_tests.rs +++ b/crates/algo/src/blur2/shape_tests.rs @@ -233,6 +233,7 @@ fn direct_36mp_image_with_small_output_is_not_rejected() { assert_eq!(result, vec![0.25; 4]); } +/// An asymmetric weighted kernel detects mirroring independently of span accumulation. #[test] fn custom_shape_coverage_matches_point_convolution_without_mirroring() { let mask = Image { rect: Rect::new(0, 0, 3, 3), ch: 1, data: vec![1.0, 0.25, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0] }; @@ -276,6 +277,7 @@ fn custom_shape_coverage_matches_point_convolution_without_mirroring() { assert_eq!(out[4 * 7 + 4], 0.0); } +/// The custom path must agree with the existing square blur, including tiled boundaries. #[test] fn custom_square_preserves_builtin_result_and_tile_boundaries() { let rect = Rect::new(-3, -2, 17, 14); @@ -293,6 +295,7 @@ fn custom_square_preserves_builtin_result_and_tile_boundaries() { exact(&tiled.read_region(rect), &ordinary.read_region(rect)); } +/// Oversized and invalid kernel metadata must be rejected before proportional allocation. #[test] fn invalid_custom_kernels_are_refused_without_allocating_their_declared_size() { for mask in [ diff --git a/crates/engine/src/cmd/atn_cmds/steps_batch.rs b/crates/engine/src/cmd/atn_cmds/steps_batch.rs index 233d885d3c1..159cb0ca7bd 100644 --- a/crates/engine/src/cmd/atn_cmds/steps_batch.rs +++ b/crates/engine/src/cmd/atn_cmds/steps_batch.rs @@ -6,10 +6,12 @@ use super::{D, Descriptor, ReferenceItem, UnicodeString, Value, json}; const ORIGINAL: &str = "__atnBatch"; +/// Reject unknown or duplicate wire keys before conversion could discard them. fn keys(d: &Descriptor, allowed: &[&str]) -> bool { d.items.iter().all(|(k, _)| allowed.iter().any(|s| k.is(s))) && allowed.iter().all(|s| d.items.iter().filter(|(k, _)| k.is(s)).count() <= 1) } +/// Read the measured list and nested serial/compatibility fields without collapsing unknown components. fn naming_from(rules: &Descriptor) -> Option { if !rules.class_id.is("fileNamingRules") || !keys(rules, &["fileNamingComponents", "Strt", "Mcnt", "Win ", "unix"]) { return None; @@ -60,6 +62,7 @@ fn naming_from(rules: &Descriptor) -> Option { Some(p) } +/// Write each literal or known component explicitly; counters must fit the signed wire field. fn naming_to(p: &Value) -> Option { let components = p.get("namingComponents")?.as_array()?; if !(1..=6).contains(&components.len()) { @@ -104,6 +107,7 @@ fn naming_to(p: &Value) -> Option { Some(d) } +/// Admit supported folder settings while leaving unrepresented input and dialog modes as whole steps. fn read(d: &Descriptor) -> Option { if !keys(d, &["null", "OvrO", "Fldr", "suppressWarnings", "suppressOpenOptions", "Usng", "T ", "Ovrd", "fileNamingRules"]) { return None; @@ -142,6 +146,7 @@ fn read(d: &Descriptor) -> Option { Some(p) } +/// Retain original metadata beside native params so an unedited save need not canonicalize the descriptor. pub(super) fn batch_from(d: &Descriptor) -> Mapped { let p = read(d).map(|mut p| { p[ORIGINAL] = json!(photocraft_paint::tile::b64_encode(&d.to_bytes())); @@ -150,6 +155,7 @@ pub(super) fn batch_from(d: &Descriptor) -> Mapped { p.map_or(Mapped::Unsupported { harmless: false }, |p| step("file.automate.batch", p)) } +/// Reuse recorded metadata only while params match; represented edits get a fresh descriptor. pub(super) fn batch_to(_: &str, p: &Value) -> Option { if p.as_object()?.keys().any(|k| { ![ diff --git a/crates/engine/src/cmd/atn_cmds/steps_lookup.rs b/crates/engine/src/cmd/atn_cmds/steps_lookup.rs index e5ae83ef9d2..5d589b28466 100644 --- a/crates/engine/src/cmd/atn_cmds/steps_lookup.rs +++ b/crates/engine/src/cmd/atn_cmds/steps_lookup.rs @@ -7,6 +7,7 @@ use super::{D, Descriptor, Value, json}; const ORIGINAL: &str = "__atnColorLookup"; const KEYS: &[&str] = &["lookupType", "Nm ", "Dthr", "profile", "LUTFormat", "LUT3DFileData", "LUT3DFileName"]; +/// Admit only measured 3D-LUT fields and parser-supported data; other profiles and settings stay whole. fn read(d: &Descriptor) -> Option<(&[u8], &'static str, String, bool)> { if d.items.iter().any(|(k, _)| !KEYS.iter().any(|key| k.is(key))) || KEYS.iter().any(|key| d.items.iter().filter(|(k, _)| k.is(key)).count() > 1) { return None; @@ -48,6 +49,7 @@ fn read(d: &Descriptor) -> Option<(&[u8], &'static str, String, bool)> { Some((bytes, format, get_text(d, "LUT3DFileName")?, get_bool(d, "Dthr")?)) } +/// Carry the original bytes into native playback without following the recorded source path. fn params(d: &Descriptor) -> Option { let (bytes, format, file_name, dither) = read(d)?; // Keep the potentially large file only in `data`; the template retains key order and @@ -67,6 +69,7 @@ fn params(d: &Descriptor) -> Option { })) } +/// Keep unsupported lookup forms intact instead of replaying only a subset of their processing. pub(super) fn from(d: &Descriptor) -> Mapped { params(d).map_or(Mapped::Unsupported { harmless: false }, |p| step("image.adjustments.colorLookup", p)) } diff --git a/crates/engine/src/cmd/atn_cmds/steps_shape_blur.rs b/crates/engine/src/cmd/atn_cmds/steps_shape_blur.rs index cf6d753da57..8678bccf18e 100644 --- a/crates/engine/src/cmd/atn_cmds/steps_shape_blur.rs +++ b/crates/engine/src/cmd/atn_cmds/steps_shape_blur.rs @@ -4,6 +4,7 @@ use super::descriptors::{PX, desc, get_text, px, text}; use super::fields::{Mapped, step}; use super::{D, Descriptor, Value, json}; +/// Admit the measured custom-shape form; the native command resolves its installed ID at playback. pub(super) fn from(d: &Descriptor) -> Mapped { let mapped = || -> Option { let D::UnitFloat { unit, value } = d.get("Rds ")? else { return None }; @@ -26,6 +27,7 @@ pub(super) fn from(d: &Descriptor) -> Mapped { mapped().map_or(Mapped::Unsupported { harmless: false }, |p| step("filter.blur.shapeBlur", p)) } +/// Refuse native geometry or target options that the recorded installed-shape reference cannot carry. pub(super) fn to(_: &str, p: &Value) -> Option { if p.as_object()?.keys().any(|key| !["radius", "shapeName", "shapeId", "shapeOriginType"].contains(&key.as_str())) { return None; diff --git a/crates/engine/src/cmd/atn_cmds/tests.rs b/crates/engine/src/cmd/atn_cmds/tests.rs index fb35c2e18e3..3ccbe9b7915 100644 --- a/crates/engine/src/cmd/atn_cmds/tests.rs +++ b/crates/engine/src/cmd/atn_cmds/tests.rs @@ -82,6 +82,7 @@ fn color_lookup_case() -> Value { json!({"data":b64(bytes),"dataEncoding":"base64","lutFormat":"cube","fileName":"identity.cube","dither":false,"__atnColorLookup":b64(&d.to_bytes())}) } +/// Keep the starting counter nested in naming rules, as recorded by the Batch dialog. fn batch_descriptor(component: &str) -> Descriptor { let rules = desc("fileNamingRules") .with("fileNamingComponents", D::List(vec![D::Descriptor(desc("fileNamingComponent").with("component", enm("fileNamingComponent", component)))])) @@ -104,12 +105,14 @@ fn batch_descriptor(component: &str) -> Descriptor { .with("fileNamingRules", D::Descriptor(rules)) } +/// Preserve the recorded template in the generic registry round-trip witness. fn batch_case() -> Value { json!({"input":"/input","output":"/output","action":"Child","set":"S","flatOutput":true,"includeSubfolders":false,"overrideSaveAs":false, "namingComponents":[{"component":"serial3"}],"startingSerial":7,"compatibility":{"macintosh":true,"windows":false,"unix":true}, "__atnBatch":b64(&batch_descriptor("threeDigit").to_bytes())}) } +/// Each documented component and portability flag must survive native conversion and save. #[test] fn batch_all_documented_components_and_compatibility_flags_round_trip() { for &(wire, native) in crate::file_cmds::BATCH_NAMING_COMPONENTS { @@ -127,6 +130,7 @@ fn batch_all_documented_components_and_compatibility_flags_round_trip() { } } +/// Unsupported modes and misplaced fields must not lose data through a partial conversion. #[test] fn batch_unknown_components_wrong_start_placement_and_unsupported_modes_stay_whole() { let mut cases = vec![batch_descriptor("unknownComponent")]; diff --git a/crates/engine/src/cmd/file_cmds/batch_naming.rs b/crates/engine/src/cmd/file_cmds/batch_naming.rs index 28a5ed9b462..df1d3e7ce38 100644 --- a/crates/engine/src/cmd/file_cmds/batch_naming.rs +++ b/crates/engine/src/cmd/file_cmds/batch_naming.rs @@ -36,6 +36,7 @@ pub(crate) const COMPONENTS: &[(&str, &str)] = &[ ("upperCaseExtension", "EXTENSION"), ]; +/// Bound structured fields before file processing; literals never pass through the legacy template parser. fn components(params: &Value) -> Result> { let Some(value) = params.get("namingComponents").filter(|v| !v.is_null()) else { return Ok(None) }; let list = value.as_array().filter(|a| (1..=6).contains(&a.len())).ok_or_else(|| bad("namingComponents needs one to six components"))?; @@ -52,6 +53,7 @@ fn components(params: &Value) -> Result> { Ok(Some(list)) } +/// Read explicit portability flags; path-containment and host-filesystem checks remain mandatory. fn compatibility(params: &Value) -> Result<(bool, bool, bool)> { let Some(value) = params.get("compatibility").filter(|v| !v.is_null()) else { return Ok((false, false, false)) }; let flags = value.as_object().ok_or_else(|| bad("compatibility must be an object"))?; @@ -65,8 +67,8 @@ fn compatibility(params: &Value) -> Result<(bool, bool, bool)> { )) } -// Serial-letter conversion from #4579 by @FabioLissi, adapted to the bounded input index. -// Adobe specifies that letters start at A independently of the numeric starting serial. +/// Serial-letter conversion from #4579 by @FabioLissi, using the one-based input index. +/// Adobe specifies that letters start at A independently of the numeric starting serial. fn letters(mut n: u64, upper: bool) -> String { let mut out = Vec::new(); while n > 0 { @@ -79,6 +81,7 @@ fn letters(mut n: u64, upper: bool) -> String { String::from_utf8(out).unwrap_or_default() } +/// Construct the entire filename in recorded order, adding a dot only for the final extension component. fn expand_components(parts: &[Value], name: &str, serial: u32, index: usize, ext: &str, date: chrono::NaiveDate) -> Result { let mut out = String::new(); for (i, part) in parts.iter().enumerate() { @@ -256,6 +259,7 @@ mod tests { use super::*; use serde_json::json; + /// Fix the date and input index so naming checks are independent of the clock and serial start. #[test] fn batch_components_cover_names_serials_letters_and_every_measured_date() { let date = chrono::NaiveDate::from_ymd_opt(2026, 11, 1).unwrap(); @@ -288,6 +292,7 @@ mod tests { assert_eq!(expand_components(&[json!({"component":"letter"})], "x", 9999, 27, "png", date).unwrap(), "ab"); } + /// Literal braces stay literal and an extension adds its dot only in the final position. #[test] fn batch_extension_position_and_literal_text_determine_the_entire_name() { let date = chrono::NaiveDate::from_ymd_opt(2026, 11, 1).unwrap(); @@ -304,6 +309,7 @@ mod tests { } } + /// Check filename admission before processing, including counter overflow and portability limits. #[test] fn batch_component_preflight_retains_bounds_platform_checks_and_serial_overflow() { let inputs = diff --git a/crates/engine/src/cmd/file_cmds/batch_run.rs b/crates/engine/src/cmd/file_cmds/batch_run.rs index 2767e5ffe73..c9a0092c3cb 100644 --- a/crates/engine/src/cmd/file_cmds/batch_run.rs +++ b/crates/engine/src/cmd/file_cmds/batch_run.rs @@ -176,6 +176,8 @@ fn same_format_takes_the_file_names_extension() { assert_eq!(same_format("/in/.hidden"), "png"); } +/// Check collisions before input reads and isolate each file in a scratch session. +/// An optional content format decouples encoding from the structured destination filename. fn process_outputs<'a>( s: &Session, outputs: impl IntoIterator, diff --git a/crates/engine/src/cmd/file_cmds/tests.rs b/crates/engine/src/cmd/file_cmds/tests.rs index 43c2fa189e2..455401016c4 100644 --- a/crates/engine/src/cmd/file_cmds/tests.rs +++ b/crates/engine/src/cmd/file_cmds/tests.rs @@ -1,6 +1,7 @@ use super::*; // Named Batch action regression adapted from #7170 by @HirthikBalaji. +/// Named action lookup retains the original #7170 behavior while rejecting recursive Batch calls. #[test] fn batch_resolves_action_by_name_and_detects_recursion() { let dir = tmp("batch-action-name"); @@ -8,7 +9,7 @@ fn batch_resolves_action_by_name_and_detects_recursion() { let out = join(&dir, "out"); std::fs::create_dir_all(&out).unwrap(); let mut s = Session::new(); - let mut action = crate::actions_cmds::Action::new("Scale".into(), vec![("image.imageSize".into(), json!({"width":16,"height":16}))]); + let mut action = crate::actions_cmds::Action::new("Scale", vec![("image.imageSize".into(), json!({"width":16,"height":16}))]); action.set = Some("Ops".into()); s.actions.list.push(action); let result = s.execute("file.automate.batch", json!({"action":"Scale","set":"Ops","input":[input.clone()],"output":out})).unwrap(); @@ -24,6 +25,7 @@ fn batch_resolves_action_by_name_and_detects_recursion() { assert!(err.to_string().contains("recursive action call"), "{err}"); } +/// Exercise saved-action replay through Batch; filename suffixes cannot change encoded image content. #[test] fn batch_structured_names_keep_image_format_and_refuse_unsupported_save_routing() { let dir = tmp("batch-component-format"); @@ -63,12 +65,12 @@ fn batch_structured_names_keep_image_format_and_refuse_unsupported_save_routing( assert!(saved["errors"].as_array().unwrap().is_empty(), "{saved}"); assert!(std::fs::read(saved["files"][0].as_str().unwrap()).unwrap().starts_with(b"\x89PNG\r\n\x1a\n")); // One composition witness: Save Actions -> Load Actions -> named Batch -> actual PNG bytes. - let mut child = crate::actions_cmds::Action::new("Child".into(), vec![]); + let mut child = crate::actions_cmds::Action::new("Child", vec![]); child.set = Some("S".into()); s.actions.list.push(child); let params = json!({"input":dir,"output":output,"action":"Child","set":"S","includeSubfolders":false,"flatOutput":true, "overrideSaveAs":false,"namingComponents":[{"text":"from-atn"}]}); - let driver = crate::actions_cmds::Action::new("Driver".into(), vec![("file.automate.batch".into(), params)]); + let driver = crate::actions_cmds::Action::new("Driver", vec![("file.automate.batch".into(), params)]); let (bytes, skipped) = crate::atn_cmds::export("S", &[&driver], &[], false).unwrap(); assert!(skipped.is_empty()); let imported = crate::atn_cmds::import(&bytes).unwrap(); diff --git a/crates/engine/tests/it/atn_color_lookup.rs b/crates/engine/tests/it/atn_color_lookup.rs index 65b85878298..e84538377e3 100644 --- a/crates/engine/tests/it/atn_color_lookup.rs +++ b/crates/engine/tests/it/atn_color_lookup.rs @@ -6,6 +6,7 @@ use serde_json::json; const CUBE: &[u8] = b"LUT_3D_SIZE 2\n1 1 1\n0 1 1\n1 0 1\n0 0 1\n1 1 0\n0 1 0\n1 0 0\n0 0 0\n"; +/// An unreadable recorded filename ensures playback depends on embedded data alone. fn descriptor(format: &str, bytes: &[u8]) -> Descriptor { let text = |s: &str| D::Text(UnicodeString::new_nul(s)); let en = |ty: &str, value: &str| D::Enumerated { type_id: Id::new(ty), value: Id::new(value) }; @@ -45,6 +46,7 @@ fn saved(s: &Session) -> Vec { photocraft_format::save_to_bytes(&s.active().unwrap().doc, &Default::default()).unwrap() } +/// Original invert tables exercise text CUBE/3DL and binary UTF-16 LOOK decoding. fn samples() -> Vec<(&'static str, Vec)> { let mut three_dl = String::from("0 1023\n"); for r in 0..2 { @@ -62,6 +64,7 @@ fn samples() -> Vec<(&'static str, Vec)> { vec![("LUTFormatCUBE", CUBE.to_vec()), ("LUTFormat3DL", three_dl.into_bytes()), ("LUTFormatLOOK", le), ("LUTFormatLOOK", be)] } +/// Compare every supported encoding and document depth with native adjustment playback and Undo. #[test] fn embedded_lookup_bytes_replay_invert_and_save_the_exact_descriptor() { for (format, bytes) in samples() { @@ -90,6 +93,7 @@ fn embedded_lookup_bytes_replay_invert_and_save_the_exact_descriptor() { } } +/// Saving an adjustment must preserve the original payload rather than a decoded substitute. #[test] fn encoded_lookup_keeps_its_bytes_in_a_saved_adjustment() { for (format, bytes) in samples() { @@ -112,6 +116,7 @@ fn encoded_lookup_keeps_its_bytes_in_a_saved_adjustment() { } } +/// An identity table isolates the nonlinear shaper through import, replay and saved adjustment bytes. #[test] fn embedded_three_dl_retains_its_nonlinear_shaper_through_action_playback() { // A two-node identity table with a four-knot shaper. Ignoring the first row @@ -155,6 +160,7 @@ fn embedded_three_dl_retains_its_nonlinear_shaper_through_action_playback() { assert_eq!(atn::parse(&out).unwrap().actions[0].items[0].descriptor, Some(bad)); } +/// Unsupported recording fields and native edits must not silently become partial lookup steps. #[test] fn unknown_lookup_forms_stay_whole_and_changed_native_steps_refuse_export() { let d = descriptor("LUTFormatCUBE", CUBE); diff --git a/crates/engine/tests/it/atn_dialog_filters.rs b/crates/engine/tests/it/atn_dialog_filters.rs index 448fe5fcc37..0a3132ea350 100644 --- a/crates/engine/tests/it/atn_dialog_filters.rs +++ b/crates/engine/tests/it/atn_dialog_filters.rs @@ -15,6 +15,7 @@ fn encoded(code: &[u8; 4], d: Descriptor) -> Vec { .unwrap() } +/// Pair measured descriptors with native params, including signed Fibers seed bits. fn cases() -> Vec<([u8; 4], Descriptor, &'static str, Value)> { let kernel: Vec = (0..25).map(|i| if i == 12 { 1 } else { 0 }).collect(); vec![ @@ -43,6 +44,7 @@ fn fixture(depth: u32) -> Session { s } +/// Compare imported actions with native execution across depths, then verify descriptor save and Undo. #[test] fn custom_and_fibers_recordings_round_trip_replay_native_settings_and_undo() { for (code, d, id, p) in cases() { @@ -70,6 +72,7 @@ fn custom_and_fibers_recordings_round_trip_replay_native_settings_and_undo() { } } +/// Malformed and unsupported forms remain complete steps instead of being partially interpreted. #[test] fn dialog_filters_keep_unrepresented_types_ranges_and_fields_whole() { for (code, d, _, _) in cases() { diff --git a/crates/engine/tests/it/atn_shape_blur.rs b/crates/engine/tests/it/atn_shape_blur.rs index 16b609310e2..56d588ae9ca 100644 --- a/crates/engine/tests/it/atn_shape_blur.rs +++ b/crates/engine/tests/it/atn_shape_blur.rs @@ -9,6 +9,7 @@ mod csh_fixture; const SHAPE_ID: &str = "original-fixture-square"; +/// The recorded display name differs from the installed ID to expose accidental name lookup. fn descriptor() -> Descriptor { Descriptor::new("null") .with("Rds ", D::UnitFloat { unit: *b"#Pxl", value: 5.0 }) @@ -54,6 +55,7 @@ fn saved(s: &Session) -> Vec { photocraft_format::save_to_bytes(&s.active().unwrap().doc, &Default::default()).unwrap() } +/// A conflicting display name must not select a different kernel; playback remains undoable. #[test] fn custom_shape_uses_installed_id_despite_name_collision_and_undoes() { let original = descriptor(); @@ -77,6 +79,7 @@ fn custom_shape_uses_installed_id_despite_name_collision_and_undoes() { } } +/// A saved Smart Filter carries geometry so reopening does not depend on ambient presets. #[test] fn custom_shape_smart_filter_keeps_geometry_across_save_without_preset_library() { let mut s = fixture(16); @@ -103,6 +106,7 @@ fn custom_shape_smart_filter_keeps_geometry_across_save_without_preset_library() assert_eq!(pixels(&reopened), expected); } +/// Exercise the CSH-to-action bridge, including duplicate imports and durable ID lookup. #[test] fn imported_csh_id_resolves_in_an_action_after_reimport_and_preference_reload() { let mut s = fixture(16); @@ -142,6 +146,7 @@ fn imported_csh_id_resolves_in_an_action_after_reimport_and_preference_reload() assert_eq!(saved(&s), before); } +/// Admission failure must leave both pixels and the Undo history untouched. #[test] fn missing_or_invalid_custom_shapes_refuse_before_document_or_history_changes() { let mut s = fixture(8); @@ -166,6 +171,7 @@ fn missing_or_invalid_custom_shapes_refuse_before_document_or_history_changes() assert_eq!(saved(&s), before); } +/// New IDs survive preferences serialization without requiring them in older stored presets. #[test] fn shape_ids_persist_and_old_preferences_without_ids_still_load() { let mut s = Session::new(); @@ -187,6 +193,7 @@ fn shape_ids_persist_and_old_preferences_without_ids_still_load() { assert!(reopened.presets.shapes.iter().flat_map(|g| &g.items).all(|shape| shape.id.is_none())); } +/// Neither unknown recording settings nor portable native geometry may be dropped during export. #[test] fn unrepresented_shape_fields_stay_whole_and_native_geometry_refuses_atn_export() { for (key, value) in [ diff --git a/crates/psd/src/csh.rs b/crates/psd/src/csh.rs index 2b6d545c2c6..a024eb675d2 100644 --- a/crates/psd/src/csh.rs +++ b/crates/psd/src/csh.rs @@ -94,6 +94,7 @@ pub fn parse(bytes: &[u8]) -> Result> { Ok(shapes) } +/// Refuse nonzero alignment bytes rather than silently discarding extra payload data as padding. fn zero_padding(bytes: &[u8]) -> Result<()> { if bytes.iter().any(|&b| b != 0) { return Err(PsdError::invalid("CSH nonzero padding"));