#1132: a damaged PSD layer section keeps the merged image instead of failing the document

Psd::parse drops the layers, records Psd::warnings and keeps the header and
merged image; the importer then imports the flattened image as one layer and
reports 'Layers could not be read'. Header damage and a missing merged image
stay hard errors.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
vangel76
2026-10-12 23:00:40 +02:00
co-authored by Claude Sonnet 5.5
parent 470ea7a3af
commit 6259bf0b57
4 changed files with 137 additions and 3 deletions
+27
View File
@@ -283,3 +283,30 @@ fn paste_svg_rejects_text_that_is_not_usable_svg() {
assert!(s.execute_checked("edit.pasteSvg", json!({})).is_err());
assert_eq!(s.active_comp().unwrap().layers.len(), 1, "nothing pasted");
}
#[test]
fn psd_with_damaged_layer_section_imports_the_flattened_image() {
let mut d = WDoc::new(30, 20);
d.layers = vec![
WLayer::solid("Back", Rect::new(0, 0, 30, 20), [0.0, 0.0, 1.0, 1.0]),
WLayer::solid("Box", Rect::new(2, 2, 8, 8), [1.0, 0.0, 0.0, 1.0]).with_blend(b"mul "),
];
let mut bytes = write(&d);
let at = bytes.windows(8).position(|w| w == b"8BIMmul ").unwrap();
bytes[at] = b'X';
let path = tmp("damaged.psd");
std::fs::write(&path, bytes).unwrap();
let mut s = Session::default();
let r = s.execute_checked("file.import", json!({"paths": [path], "importAs": "composition"})).unwrap();
// Photoshop import warnings are reported with the import's `errors` (as for adjustment layers).
let warnings = r["errors"].as_array().unwrap();
assert_eq!(warnings.len(), 1, "{r}");
assert!(warnings[0].as_str().unwrap().contains("Layers could not be read"), "{r}");
let cid = effectcraft_project::ItemId(r["comps"][0].as_u64().unwrap());
let c = s.project.comp(cid).unwrap().clone();
assert_eq!((c.width, c.height), (30, 20));
assert_eq!(c.layers.len(), 1);
let LayerSource::Footage { item } = c.layers[0].source else { panic!("footage") };
let ItemKind::Footage(f) = &s.project.item(item).unwrap().kind else { panic!() };
assert!(f.layer.is_none(), "the merged image, not a Photoshop layer");
}