From 80d4e2395e00530e5296c3178ece13d583a0ec7d Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 03:26:23 -0500 Subject: [PATCH] test(webp): cover lossy alpha container and XMP framing --- crates/webp/src/anim.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/webp/src/anim.rs b/crates/webp/src/anim.rs index d407819e9..7d63c75b7 100644 --- a/crates/webp/src/anim.rs +++ b/crates/webp/src/anim.rs @@ -230,6 +230,23 @@ mod tests { assert_eq!(&file[anim + 8..anim + 14], &[1, 2, 3, 4, 0, 0]); } + #[test] + fn lossy_container_keeps_alpha_payload_padding_and_xmp() { + // Container-only fixture: the writer must not reinterpret an encoder's VP8 bytes. + let vp8 = [11, 22, 33]; + let alpha = [128]; + let f = frame(Payload::Lossy { vp8: &vp8, alpha: Some(&alpha) }, 0, 0, 1, 1, 17); + let file = animation(1, 1, &[f], &AnimOptions { xmp: Some(b"xmp"), ..Default::default() }).unwrap(); + let info = scan(&file, 10).unwrap(); + assert!(info.alpha && info.complete); + assert_eq!(info.frames[0].duration_ms, 17); + let at = file.windows(4).position(|c| c == b"ANMF").unwrap(); + let payload = at + 8 + 16; + assert_eq!(&file[payload..payload + 10], &[b'A', b'L', b'P', b'H', 2, 0, 0, 0, 0, 128]); + assert_eq!(&file[payload + 10..payload + 22], &[b'V', b'P', b'8', b' ', 3, 0, 0, 0, 11, 22, 33, 0]); + assert_eq!(&file[file.len() - 12..], &[b'X', b'M', b'P', b' ', 3, 0, 0, 0, b'x', b'm', b'p', 0]); + } + #[test] fn what_does_not_fit_is_refused() { let px = vp8l(2, 2, [0; 4]);