From 3b53b3a153ef21b07492c3640582958fe6902d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 09:34:48 +0300 Subject: [PATCH] B7: ec-vp9 one validate() for bit depth and 8192x4352 area guard (was 2 copies in decode_one and decode_syntax); no output change --- crates/ec-vp9/src/decode.rs | 42 ++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/crates/ec-vp9/src/decode.rs b/crates/ec-vp9/src/decode.rs index 3080c2d8..292358a5 100644 --- a/crates/ec-vp9/src/decode.rs +++ b/crates/ec-vp9/src/decode.rs @@ -90,6 +90,22 @@ struct Planes { /// before any picture or mode-info buffer is sized from them (fuzz regression: a 24580-wide key frame). const MAX_LUMA_SAMPLES: u64 = 8192 * 4352; +fn validate(hdr: &FrameHeader) -> Result<()> { + if hdr.bit_depth != 8 && hdr.bit_depth != 10 && hdr.bit_depth != 12 { + return Err(Error::unsupported( + format!("vp9 bit depth {}", hdr.bit_depth), + "this lane decodes 8-, 10- and 12-bit only", + )); + } + if u64::from(hdr.width) * u64::from(hdr.height) > MAX_LUMA_SAMPLES { + return Err(Error::unsupported( + format!("vp9 frame {}x{}", hdr.width, hdr.height), + "this lane decodes up to VP9 level 6.2 (8192x4352 luma samples)", + )); + } + Ok(()) +} + impl Planes { /// A frame scratch at the 64-multiple ALIGNED extent, filled with the /// neutral grey `1 << (bd - 1)` (`128` at 8-bit, `512` at 10-bit). The @@ -310,18 +326,7 @@ impl Decoder { None => Err(corrupt("show_existing_frame names an empty slot")), }; } - if hdr.bit_depth != 8 && hdr.bit_depth != 10 && hdr.bit_depth != 12 { - return Err(Error::unsupported( - format!("vp9 bit depth {}", hdr.bit_depth), - "this lane decodes 8-, 10- and 12-bit only", - )); - } - if u64::from(hdr.width) * u64::from(hdr.height) > MAX_LUMA_SAMPLES { - return Err(Error::unsupported( - format!("vp9 frame {}x{}", hdr.width, hdr.height), - "this lane decodes up to VP9 level 6.2 (8192x4352 luma samples)", - )); - } + validate(&hdr)?; // One index per decoded frame (the dumps' `frame=` field), so this // path and `decode_syntax` label the same frame the same way. let index = self.decode_index; @@ -474,18 +479,7 @@ impl Decoder { if hdr.show_existing_frame { continue; } - if hdr.bit_depth != 8 && hdr.bit_depth != 10 && hdr.bit_depth != 12 { - return Err(Error::unsupported( - format!("vp9 bit depth {}", hdr.bit_depth), - "this lane decodes 8-, 10- and 12-bit only", - )); - } - if u64::from(hdr.width) * u64::from(hdr.height) > MAX_LUMA_SAMPLES { - return Err(Error::unsupported( - format!("vp9 frame {}x{}", hdr.width, hdr.height), - "this lane decodes up to VP9 level 6.2 (8192x4352 luma samples)", - )); - } + validate(&hdr)?; if hdr.frame_type == FrameType::Key { // Propagate: a corrupt keyframe leaves a half-updated frame // context, prev-frame MV field and reference slots behind, so