Files
craft-libs/crates/video/tests/apv/hostile_args.rs
Dylan M. Taylor 7f8a4eed58 craft-video: APV decoder and encoder from FilmCraft (apv) (#865)
FilmCraft's crates/apv at 4bec22bd moves to craft_video::apv: the decoder
(craft_video::apv::decode, feature `apv-decode`), the encoder
(craft_video::apv::encode, feature `apv-encode`), both re-exported at the
module root; `apv` turns on both. Sources, README and tests (ffmpeg oracle,
alpha, mutation and hostile sweeps).

Changes in the move: craft_media::bitstream and craft-media-testkit instead of
FilmCraft's, one test target (tests/apv), crate paths.

New: DecodeOptions::memory_budget (craft_video::budget) refuses a frame whose
samples do not fit before anything is allocated (Error::MemoryBudget).

Fixed, each with a test that fails without it (debug-build overflows):
- EncoderConfig::new multiplied width, height and 30 in u64 without a check.
- Frame::new shifted by the bit depth unchecked (32 and above overflow).
- The public transform functions shifted by a bit depth outside 10..=16.
2026-11-11 17:26:22 -05:00

22 lines
826 B
Rust

//! Out-of-range arguments to the public constructors are errors or clamped, never arithmetic
//! overflow (a panic in a debug build).
use craft_video::apv::*;
#[test]
fn encoder_config_for_absurd_dimensions_does_not_overflow() {
for (w, h) in [(u32::MAX, u32::MAX), (1 << 31, 1 << 31), (u32::MAX, 1), (0, 0)] {
let cfg = EncoderConfig::new(Profile::P4444_12, w, h);
assert!(Encoder::with_config(cfg).is_err(), "{w}x{h}");
}
}
#[test]
fn frame_with_an_absurd_bit_depth_does_not_overflow() {
for depth in [0, 7, 17, 31, 32, 40, 255] {
let f = Frame::new(2, 2, ChromaFormat::Yuv4444, depth, true);
assert_eq!((f.bit_depth, f.y.len(), f.alpha.map(|a| a.len())), (depth, 4, Some(4)));
}
assert_eq!(Frame::new(1, 1, ChromaFormat::Yuv422, 10, true).alpha, Some(vec![1023]));
}