forge
Explore
Log in

Don't you dare go Hollow

Refuse non-SPLIT inter SB part64 by name instead of desyncing

Browse files at this commit

6e8fc0b9eb7e571727d4e9965512f410e5d05efeAhmet Kaan GümüşParent: 5a8c7fe
  • fix
    • refuse non-SPLIT inter SB part64 by name instead of desyncing
Show full message
fix(av1): refuse non-SPLIT inter SB part64 by name instead of desyncing

decode_inter_frame_tile_with_cdfs read part64 then `let _ = part64;`,
blindly recursing every superblock as SPLIT. A real non-SPLIT part64 in
an inter frame would silently desync rather than refuse. Now the value
is kept (SPLIT is still inferred for the forced-half/straddle cases,
matching the intra tile's own three-way write) and any other value
returns a named unsupported() error before the quadrant recursion runs.

New refusal string: "an inter SB-level partition type other than SPLIT
(this decoder's inter tile path only recurses a superblock as SPLIT)".

Test: a_non_split_inter_sb_partition_refuses_by_name_instead_of_desyncing
hand-writes a PARTITION_HORZ part64 symbol and asserts the named error
comes back instead of garbage decode.
crates/ec-av1/src/decode.rsmodified+60 -5
@@ -9393,25 +9393,40 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
93939393 sb_c * SB_MI + SB_MI / 2 < mi_cols,
93949394 sb_r * SB_MI + SB_MI / 2 < mi_rows,
93959395 );
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) {
93979404 (true, true) => {
9398- let part64 = dec.symbol(&mut cdfs.partition_w64[sb_ctx]);
9405+ let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]);
93999406 if std::env::var_os("EC_AV1_TRACE").is_some() {
94009407 eprintln!(
9401- "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={part64}",
9408+ "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p}",
94029409 sb_r * SB_MI,
94039410 sb_c * SB_MI
94049411 );
94059412 }
9406- let _ = part64;
9413+ p
94079414 }
94089415 (true, false) => {
94099416 dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE));
9417+ PARTITION_SPLIT
94109418 }
94119419 (false, true) => {
94129420 dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE));
9421+ PARTITION_SPLIT
94139422 }
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+ ));
94159430 }
94169431
94179432 for quadrant in 0..4 {
@@ -10840,6 +10855,46 @@ mod tests {
1084010855 );
1084110856 }
1084210857
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+
1084310898 // ffmpeg cross-oracle: an independent decoder (not this crate's own
1084410899 // encoder-side reconstruction) agrees with what this module decodes,
1084510900 // duplicating `crate::encode`'s own `#[cfg(test)]` helpers of the same