forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'simplify/b7' into simplify/w1a

Browse files at this commit

41c726614d8dc5c8ce25dfed802c7d4305d16525Ahmet Kaan GümüşParent: eb345bb406f455
crates/ec-vp9-syntax/src/superframe.rsmodified+13 -1
@@ -52,9 +52,14 @@ pub fn split(chunk: &[u8]) -> Result<Vec<&[u8]>> {
5252 "VP9 superframe: frame {i} of {frames} runs past the chunk ({size} bytes at {offset})"
5353 ))
5454 })?;
55- out.push(&chunk[offset..end]);
55+ if end > offset {
56+ out.push(&chunk[offset..end]);
57+ }
5658 offset = end;
5759 }
60+ if out.is_empty() {
61+ return Err(Error::corrupt("VP9 superframe: index names no frame data"));
62+ }
5863 Ok(out)
5964 }
6065
@@ -102,6 +107,13 @@ mod tests {
102107 assert_eq!(frames[2][0], 2);
103108 }
104109
110+ #[test]
111+ fn zero_size_entry_is_skipped() {
112+ let chunk = pack(&[3, 0, 5], 1);
113+ let frames = split(&chunk).unwrap();
114+ assert_eq!(frames.iter().map(|f| f.len()).collect::<Vec<_>>(), [3, 5]);
115+ }
116+
105117 #[test]
106118 fn oversized_entry_is_corrupt() {
107119 let mut chunk = pack(&[3, 5], 1);
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