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 commit3b53b3a153ef21b07492c3640582958fe6902d22Parent: 22f0f3f1 changed file +18 -24
- crates/ec-vp9/src/decode.rs +18 -24
crates/ec-vp9/src/decode.rsmodified+18 -24
| @@ -90,6 +90,22 @@ struct Planes { | ||
| 90 | 90 | /// before any picture or mode-info buffer is sized from them (fuzz regression: a 24580-wide key frame). |
| 91 | 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 | 109 | impl Planes { |
| 94 | 110 | /// A frame scratch at the 64-multiple ALIGNED extent, filled with the |
| 95 | 111 | /// neutral grey `1 << (bd - 1)` (`128` at 8-bit, `512` at 10-bit). The |
| @@ -310,18 +326,7 @@ impl Decoder { | ||
| 310 | 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 { | |
| 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)?; | |
| 325 | 330 | // One index per decoded frame (the dumps' `frame=` field), so this |
| 326 | 331 | // path and `decode_syntax` label the same frame the same way. |
| 327 | 332 | let index = self.decode_index; |
| @@ -474,18 +479,7 @@ impl Decoder { | ||
| 474 | 479 | if hdr.show_existing_frame { |
| 475 | 480 | continue; |
| 476 | 481 | } |
| 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)?; | |
| 489 | 483 | if hdr.frame_type == FrameType::Key { |
| 490 | 484 | // Propagate: a corrupt keyframe leaves a half-updated frame |
| 491 | 485 | // context, prev-frame MV field and reference slots behind, so |