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 | /// 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 |