test(io): a PSB's lnk2/pths/cinf are written as 8B64 with an 8-byte length (#7937)

This commit is contained in:
Korg1ch
2026-10-20 13:38:41 +03:00
parent c706938bde
commit 09749739ad
+29
View File
@@ -2084,6 +2084,35 @@ mod tests {
assert_eq!(signatures(true), vec![(*b"8B64", *b"FMsk"), (*b"8BIM", *b"Patt")], "a PSB keeps 8B64");
}
/// A PSB writes every global block with an 8-byte length as `8B64`, the way Photoshop does:
/// kept from a PSD source, `lnk2`, `pths` and `cinf` arrive as `8BIM`, and with that signature
/// and the PSB's 8-byte length Photoshop 27.11 refused the whole file (#7937). Blocks with a
/// 4-byte length keep `8BIM`, and a PSD keeps `8BIM` throughout.
#[test]
fn psb_writes_long_length_blocks_as_8b64() {
let mut doc = document(4, 4);
doc.metadata.psd_global_blocks = vec![
(*b"8BIM", *b"cinf", std::sync::Arc::new(vec![0, 0, 0, 16, 0, 0, 0, 0])),
(*b"8BIM", *b"pths", std::sync::Arc::new(vec![0, 0, 0, 16, 0, 0, 0, 0])),
(*b"8BIM", *b"Patt", std::sync::Arc::new(Vec::new())),
];
let written = |force_psb| {
let opts = PsdExportOptions { force_psb, ..PsdExportOptions::default() };
let bytes = document_to_psd_with(&doc, &opts).0.to_bytes().unwrap();
let file = PsdFile::from_bytes(&bytes).unwrap();
let blocks = file.global_blocks.iter().map(|b| (b.signature, b.key, b.data.len())).collect::<Vec<_>>();
(bytes, blocks)
};
let (bytes, blocks) = written(true);
assert_eq!(blocks, vec![(*b"8B64", *b"cinf", 8), (*b"8B64", *b"pths", 8), (*b"8BIM", *b"Patt", 0)]);
// On disk: the signature, the key, then the 8-byte length.
let at = bytes.windows(8).position(|w| w == b"8B64cinf").expect("8B64cinf in the file");
assert_eq!(bytes.get(at + 8..at + 16), Some(&[0u8, 0, 0, 0, 0, 0, 0, 8][..]));
assert!(!bytes.windows(8).any(|w| w == b"8BIMcinf" || w == b"8BIMpths"));
let (_, blocks) = written(false);
assert_eq!(blocks, vec![(*b"8BIM", *b"cinf", 8), (*b"8BIM", *b"pths", 8), (*b"8BIM", *b"Patt", 0)], "a PSD keeps 8BIM");
}
/// A layered document with transparency in the merged image and an alpha channel: the name
/// and DisplayInfo resources hold one entry per extra channel, the merged transparency first,
/// as in every file Photoshop opens (one short, Photoshop 27.11 refused the file with "Could