Merge branch 'simplify/b7' into simplify/w1a
Browse files at this commit2 changed files +31 -25
crates/ec-vp9-syntax/src/superframe.rsmodified+13 -1
| @@ -52,9 +52,14 @@ pub fn split(chunk: &[u8]) -> Result<Vec<&[u8]>> { | |||
| 52 | "VP9 superframe: frame {i} of {frames} runs past the chunk ({size} bytes at {offset})" | 52 | "VP9 superframe: frame {i} of {frames} runs past the chunk ({size} bytes at {offset})" |
| 53 | )) | 53 | )) |
| 54 | })?; | 54 | })?; |
| 55 | - out.push(&chunk[offset..end]); | 55 | + if end > offset { |
| 56 | + out.push(&chunk[offset..end]); | ||
| 57 | + } | ||
| 56 | offset = end; | 58 | offset = end; |
| 57 | } | 59 | } |
| 60 | + if out.is_empty() { | ||
| 61 | + return Err(Error::corrupt("VP9 superframe: index names no frame data")); | ||
| 62 | + } | ||
| 58 | Ok(out) | 63 | Ok(out) |
| 59 | } | 64 | } |
| 60 | 65 | ||
| @@ -102,6 +107,13 @@ mod tests { | |||
| 102 | assert_eq!(frames[2][0], 2); | 107 | assert_eq!(frames[2][0], 2); |
| 103 | } | 108 | } |
| 104 | 109 | ||
| 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 | + | ||
| 105 | #[test] | 117 | #[test] |
| 106 | fn oversized_entry_is_corrupt() { | 118 | fn oversized_entry_is_corrupt() { |
| 107 | let mut chunk = pack(&[3, 5], 1); | 119 | let mut chunk = pack(&[3, 5], 1); |
crates/ec-vp9/src/decode.rsmodified+18 -24
| @@ -90,6 +90,22 @@ struct Planes { | |||
| 90 | /// before any picture or mode-info buffer is sized from them (fuzz regression: a 24580-wide key frame). | 90 | /// before any picture or mode-info buffer is sized from them (fuzz regression: a 24580-wide key frame). |
| 91 | const MAX_LUMA_SAMPLES: u64 = 8192 * 4352; | 91 | const MAX_LUMA_SAMPLES: u64 = 8192 * 4352; |
| 92 | 92 | ||
| 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 | + | ||
| 93 | impl Planes { | 109 | impl Planes { |
| 94 | /// A frame scratch at the 64-multiple ALIGNED extent, filled with the | 110 | /// A frame scratch at the 64-multiple ALIGNED extent, filled with the |
| 95 | /// neutral grey `1 << (bd - 1)` (`128` at 8-bit, `512` at 10-bit). The | 111 | /// neutral grey `1 << (bd - 1)` (`128` at 8-bit, `512` at 10-bit). The |
| @@ -310,18 +326,7 @@ impl Decoder { | |||
| 310 | None => Err(corrupt("show_existing_frame names an empty slot")), | 326 | None => Err(corrupt("show_existing_frame names an empty slot")), |
| 311 | }; | 327 | }; |
| 312 | } | 328 | } |
| 313 | - if hdr.bit_depth != 8 && hdr.bit_depth != 10 && hdr.bit_depth != 12 { | 329 | + validate(&hdr)?; |
| 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 | - } | ||
| 325 | // One index per decoded frame (the dumps' `frame=` field), so this | 330 | // One index per decoded frame (the dumps' `frame=` field), so this |
| 326 | // path and `decode_syntax` label the same frame the same way. | 331 | // path and `decode_syntax` label the same frame the same way. |
| 327 | let index = self.decode_index; | 332 | let index = self.decode_index; |
| @@ -474,18 +479,7 @@ impl Decoder { | |||
| 474 | if hdr.show_existing_frame { | 479 | if hdr.show_existing_frame { |
| 475 | continue; | 480 | continue; |
| 476 | } | 481 | } |
| 477 | - if hdr.bit_depth != 8 && hdr.bit_depth != 10 && hdr.bit_depth != 12 { | 482 | + validate(&hdr)?; |
| 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 | - } | ||
| 489 | if hdr.frame_type == FrameType::Key { | 483 | if hdr.frame_type == FrameType::Key { |
| 490 | // Propagate: a corrupt keyframe leaves a half-updated frame | 484 | // Propagate: a corrupt keyframe leaves a half-updated frame |
| 491 | // context, prev-frame MV field and reference slots behind, so | 485 | // context, prev-frame MV field and reference slots behind, so |