Refuse non-SPLIT inter SB part64 by name instead of desyncing
Browse files at this commit6e8fc0b9eb7e571727d4e9965512f410e5d05efeParent: 5a8c7fe- fix
- refuse non-SPLIT inter SB part64 by name instead of desyncing
1 changed file +60 -5
- crates/ec-av1/src/decode.rs +60 -5
crates/ec-av1/src/decode.rsmodified+60 -5
| @@ -9393,25 +9393,40 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9393 | 9393 | sb_c * SB_MI + SB_MI / 2 < mi_cols, |
| 9394 | 9394 | sb_r * SB_MI + SB_MI / 2 < mi_rows, |
| 9395 | 9395 | ); |
| 9396 | - match (has_cols, has_rows) { | |
| 9396 | + // The straddle cases (one or both halves outside the true | |
| 9397 | + // frame) never carry a real alphabet symbol -- spec forces | |
| 9398 | + // SPLIT there (mirrors the intra key-frame tile's own | |
| 9399 | + // three-way write above). Only the (true, true) case can name | |
| 9400 | + // a non-SPLIT value, and this loop below only ever recurses as | |
| 9401 | + // SPLIT -- so a real non-SPLIT part64 here must refuse by name | |
| 9402 | + // instead of silently decoding as SPLIT and desyncing. | |
| 9403 | + let part64 = match (has_cols, has_rows) { | |
| 9397 | 9404 | (true, true) => { |
| 9398 | - let part64 = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); | |
| 9405 | + let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); | |
| 9399 | 9406 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 9400 | 9407 | eprintln!( |
| 9401 | - "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={part64}", | |
| 9408 | + "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p}", | |
| 9402 | 9409 | sb_r * SB_MI, |
| 9403 | 9410 | sb_c * SB_MI |
| 9404 | 9411 | ); |
| 9405 | 9412 | } |
| 9406 | - let _ = part64; | |
| 9413 | + p | |
| 9407 | 9414 | } |
| 9408 | 9415 | (true, false) => { |
| 9409 | 9416 | dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)); |
| 9417 | + PARTITION_SPLIT | |
| 9410 | 9418 | } |
| 9411 | 9419 | (false, true) => { |
| 9412 | 9420 | dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)); |
| 9421 | + PARTITION_SPLIT | |
| 9413 | 9422 | } |
| 9414 | - (false, false) => {} | |
| 9423 | + (false, false) => PARTITION_SPLIT, | |
| 9424 | + }; | |
| 9425 | + if part64 != PARTITION_SPLIT { | |
| 9426 | + return Err(unsupported( | |
| 9427 | + "an inter SB-level partition type other than SPLIT (this decoder's \ | |
| 9428 | + inter tile path only recurses a superblock as SPLIT)", | |
| 9429 | + )); | |
| 9415 | 9430 | } |
| 9416 | 9431 | |
| 9417 | 9432 | for quadrant in 0..4 { |
| @@ -10840,6 +10855,46 @@ mod tests { | ||
| 10840 | 10855 | ); |
| 10841 | 10856 | } |
| 10842 | 10857 | |
| 10858 | + /// An inter tile's SB-level `part64` used to be read and thrown away | |
| 10859 | + /// (`let _ = part64;`), recursing as SPLIT unconditionally -- a real | |
| 10860 | + /// non-SPLIT value there silently desynced the whole tile instead of | |
| 10861 | + /// refusing. Hand-writes a single whole superblock's `part64 = HORZ` | |
| 10862 | + /// symbol (never produced by this crate's own encoder, which only ever | |
| 10863 | + /// writes NONE/SPLIT at this level, but a real aomenc-class encoder can) | |
| 10864 | + /// and asserts this decoder refuses by name rather than decoding garbage. | |
| 10865 | + #[test] | |
| 10866 | + fn a_non_split_inter_sb_partition_refuses_by_name_instead_of_desyncing() { | |
| 10867 | + use crate::msac::SymbolEncoder; | |
| 10868 | + let mut cdfs = Cdfs::new(q_ctx_of(40)); | |
| 10869 | + let mut enc = SymbolEncoder::new(); | |
| 10870 | + enc.symbol(PARTITION_HORZ, &mut cdfs.partition_w64[0]); | |
| 10871 | + let data = enc.finish(); | |
| 10872 | + let reference = crate::encode::Picture::grey(64, 64); | |
| 10873 | + let err = decode_inter_frame_tile( | |
| 10874 | + &data, | |
| 10875 | + 16, | |
| 10876 | + 16, | |
| 10877 | + 40, | |
| 10878 | + 64, | |
| 10879 | + 64, | |
| 10880 | + &reference, | |
| 10881 | + [None; 8], | |
| 10882 | + &CdefParams::default(), | |
| 10883 | + &LoopFilterParams::default(), | |
| 10884 | + false, | |
| 10885 | + false, | |
| 10886 | + Some(mc::InterpFilterKind::Regular), | |
| 10887 | + false, | |
| 10888 | + false, | |
| 10889 | + ) | |
| 10890 | + .unwrap_err(); | |
| 10891 | + let msg = err.to_string(); | |
| 10892 | + assert!( | |
| 10893 | + msg.contains("SPLIT"), | |
| 10894 | + "expected the named inter-SB-partition refusal, got: {msg}" | |
| 10895 | + ); | |
| 10896 | + } | |
| 10897 | + | |
| 10843 | 10898 | // ffmpeg cross-oracle: an independent decoder (not this crate's own |
| 10844 | 10899 | // encoder-side reconstruction) agrees with what this module decodes, |
| 10845 | 10900 | // duplicating `crate::encode`'s own `#[cfg(test)]` helpers of the same |