forge
Explore
Log in

Don't you dare go Hollow

B7: ec-vp9 one validate() for bit depth and 8192x4352 area guard (was 2 copies in decode_one and decode_syntax); no output change

Browse files at this commit

3b53b3a153ef21b07492c3640582958fe6902d22Ahmet Kaan GümüşParent: 22f0f3f
crates/ec-vp9/src/decode.rsmodified+18 -24
@@ -90,6 +90,22 @@ struct Planes {
9090 /// before any picture or mode-info buffer is sized from them (fuzz regression: a 24580-wide key frame).
9191 const MAX_LUMA_SAMPLES: u64 = 8192 * 4352;
9292
93+fn validate(hdr: &FrameHeader) -> Result<()> {
94+ if hdr.bit_depth != 8 && hdr.bit_depth != 10 && hdr.bit_depth != 12 {
95+ return Err(Error::unsupported(
96+ format!("vp9 bit depth {}", hdr.bit_depth),
97+ "this lane decodes 8-, 10- and 12-bit only",
98+ ));
99+ }
100+ if u64::from(hdr.width) * u64::from(hdr.height) > MAX_LUMA_SAMPLES {
101+ return Err(Error::unsupported(
102+ format!("vp9 frame {}x{}", hdr.width, hdr.height),
103+ "this lane decodes up to VP9 level 6.2 (8192x4352 luma samples)",
104+ ));
105+ }
106+ Ok(())
107+}
108+
93109 impl Planes {
94110 /// A frame scratch at the 64-multiple ALIGNED extent, filled with the
95111 /// neutral grey `1 << (bd - 1)` (`128` at 8-bit, `512` at 10-bit). The
@@ -310,18 +326,7 @@ impl Decoder {
310326 None => Err(corrupt("show_existing_frame names an empty slot")),
311327 };
312328 }
313- if hdr.bit_depth != 8 && hdr.bit_depth != 10 && hdr.bit_depth != 12 {
314- return Err(Error::unsupported(
315- format!("vp9 bit depth {}", hdr.bit_depth),
316- "this lane decodes 8-, 10- and 12-bit only",
317- ));
318- }
319- if u64::from(hdr.width) * u64::from(hdr.height) > MAX_LUMA_SAMPLES {
320- return Err(Error::unsupported(
321- format!("vp9 frame {}x{}", hdr.width, hdr.height),
322- "this lane decodes up to VP9 level 6.2 (8192x4352 luma samples)",
323- ));
324- }
329+ validate(&hdr)?;
325330 // One index per decoded frame (the dumps' `frame=` field), so this
326331 // path and `decode_syntax` label the same frame the same way.
327332 let index = self.decode_index;
@@ -474,18 +479,7 @@ impl Decoder {
474479 if hdr.show_existing_frame {
475480 continue;
476481 }
477- if hdr.bit_depth != 8 && hdr.bit_depth != 10 && hdr.bit_depth != 12 {
478- return Err(Error::unsupported(
479- format!("vp9 bit depth {}", hdr.bit_depth),
480- "this lane decodes 8-, 10- and 12-bit only",
481- ));
482- }
483- if u64::from(hdr.width) * u64::from(hdr.height) > MAX_LUMA_SAMPLES {
484- return Err(Error::unsupported(
485- format!("vp9 frame {}x{}", hdr.width, hdr.height),
486- "this lane decodes up to VP9 level 6.2 (8192x4352 luma samples)",
487- ));
488- }
482+ validate(&hdr)?;
489483 if hdr.frame_type == FrameType::Key {
490484 // Propagate: a corrupt keyframe leaves a half-updated frame
491485 // context, prev-frame MV field and reference slots behind, so