Files
craft-libs/crates/psd/fuzz/fuzz_targets/parse.rs
Dylan M. Taylor ee78a9bd46 craft-psd: Photoshop PSD/PSB reader and writer, moved from PhotoCraft (#875)
PhotoCraft's `photocraft-psd` crate (crates/psd at storytold/photocraft
63b641b55e54bf8f5c83efd977fdb16a2c255431) as `craft-psd`: the lossless
PSD/PSB model, reader, writer and builder, descriptors, the Photoshop
resource files that share its primitives (.abr, .asl, .aco, .act, .ase,
.grd, .pat, .atn, .csh, .shc) and the Photoshop blocks of a layered TIFF.
The crate had no dependency on any other PhotoCraft crate.

Code is unchanged apart from the crate name, craft-libs' rustfmt width,
comments that named other PhotoCraft crates, issue references (now
`photocraft#N`), and the corpus tests' directory (`CRAFT_PSD_CORPUS` or
`corpus/` at the workspace root). Tests, proptests, fuzz targets and
fixtures move with it.

Part of #778, #786.
2026-11-11 17:00:33 -05:00

28 lines
1000 B
Rust

//! Fuzz the full parser, and exercise writer/decoders on anything that parses.
#![no_main]
use libfuzzer_sys::fuzz_target;
use craft_psd::PsdFile;
fuzz_target!(|data: &[u8]| {
let Ok(f) = PsdFile::from_bytes(data) else { return };
// Anything written must re-parse and be byte stable from then on.
// (Byte comparison rather than model equality, since NaN != NaN.)
if let Ok(out) = f.to_bytes() {
let g = PsdFile::from_bytes(&out).expect("re-parse of written file");
assert_eq!(g.to_bytes().expect("re-write"), out);
}
// Keep decoding bounded: only small images.
if u64::from(f.header.width) * u64::from(f.header.height) <= 1 << 20 {
let _ = f.decode_merged();
let _ = f.composite_rgba8();
for l in f.iter_layers() {
if l.record.rect.width() * l.record.rect.height() <= 1 << 20 {
let _ = l.rgba8();
let _ = l.user_mask();
}
}
}
let _ = f.layer_tree();
});