Files
craft-libs/crates/psd/fuzz/fuzz_targets/resources.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

25 lines
1.2 KiB
Rust

//! Fuzz the typed image-resource views: `ImageResource::parsed` for an arbitrary resource id, plus
//! the standalone `ResolutionInfo` and `VersionInfo` parsers. All must return `Ok` / `Err` / `None`
//! (and `xmp_str` an `Option`), never panic. A parsed `ResolutionInfo` (16 fixed bytes) must be
//! stable across a byte round trip. The first two bytes pick the id so every typed branch is
//! reachable; the rest is the resource data.
#![no_main]
use libfuzzer_sys::fuzz_target;
use craft_psd::resources::{ImageResource, ResolutionInfo, VersionInfo};
fuzz_target!(|data: &[u8]| {
let (id, body) = match data.split_first_chunk::<2>() {
Some((p, rest)) => (u16::from_be_bytes(*p), rest.to_vec()),
None => (0u16, data.to_vec()),
};
let r = ImageResource::new(id, body.clone());
let _ = r.parsed();
let _ = r.xmp_str();
if let Ok(ri) = ResolutionInfo::from_bytes(&body) {
let round = ResolutionInfo::from_bytes(&ri.to_bytes()).expect("resolution info re-parses");
assert_eq!(round, ri, "ResolutionInfo is not stable across a round trip");
}
if let Ok(vi) = VersionInfo::from_bytes(&body) {
let _ = vi.to_bytes();
}
});