mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-12 11:13:55 +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.
21 lines
1.2 KiB
Rust
21 lines
1.2 KiB
Rust
//! Fuzz the pattern parsers: the `Patt` / `Pat2` / `Pat3` tagged blocks and standalone `.pat`
|
|
//! files. Any input must return `Ok` or `Err`, never panic. The channel offsets and padding a
|
|
//! hostile file can carry are wire artifacts, not fields of `PsdPattern`, so a parsed pattern must
|
|
//! survive a write/parse round trip unchanged -- a stronger invariant than byte stability, which
|
|
//! would also hold if the writer silently normalised a field away.
|
|
#![no_main]
|
|
use libfuzzer_sys::fuzz_target;
|
|
use craft_psd::patterns::{parse_pat_file, parse_pattern_block, write_pat_file, write_pattern_block};
|
|
fuzz_target!(|data: &[u8]| {
|
|
if let Ok(ps) = parse_pattern_block(data) {
|
|
let out = write_pattern_block(&ps).expect("a parsed pattern block must be writable");
|
|
let back = parse_pattern_block(&out).expect("a written pattern block must re-parse");
|
|
assert_eq!(back, ps, "a pattern block does not survive a write/parse round trip");
|
|
}
|
|
if let Ok(ps) = parse_pat_file(data) {
|
|
let out = write_pat_file(&ps).expect("a parsed .pat must be writable");
|
|
let back = parse_pat_file(&out).expect("a written .pat must re-parse");
|
|
assert_eq!(back, ps, "a .pat file does not survive a write/parse round trip");
|
|
}
|
|
});
|