mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-12 08:52:32 +00:00
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.
22 lines
1.2 KiB
Rust
22 lines
1.2 KiB
Rust
//! Fuzz the `.aco` Photoshop Color Swatches parser: any input must return `Ok` or `Err`, never
|
|
//! panic; anything that parses must round-trip through `write` and re-parse with the same swatch
|
|
//! count, and no name may exceed the name-unit cap.
|
|
//!
|
|
//! `MAX_SWATCHES` is `u16::MAX` and the on-disk count is a `u16`, so the count is unfalsifiable by
|
|
//! construction; the assertion is kept as documentation of that invariant, not as a check that can
|
|
//! fail. The name cap, which is reachable, is the one that bites.
|
|
#![no_main]
|
|
use libfuzzer_sys::fuzz_target;
|
|
use craft_psd::aco;
|
|
fuzz_target!(|data: &[u8]| {
|
|
let Ok(f) = aco::parse(data) else { return };
|
|
assert!(f.swatches.len() <= aco::MAX_SWATCHES, "{} swatches exceeds MAX_SWATCHES", f.swatches.len());
|
|
for s in &f.swatches {
|
|
assert!(s.name.encode_utf16().count() <= aco::MAX_NAME_UNITS, "name longer than MAX_NAME_UNITS");
|
|
}
|
|
let out = aco::write(&f.swatches).expect("a parsed .aco must be writable");
|
|
let back = aco::parse(&out).expect("a written .aco must re-parse");
|
|
assert_eq!(back.swatches.len(), f.swatches.len(), "swatch count changed across a round trip");
|
|
assert_eq!(aco::write(&back.swatches).expect("rewritable"), out, "a second round trip is not byte-stable");
|
|
});
|