forge
Explore
Log in

Don't you dare go Hollow

An intra block in an INTER frame reads the no-CFL uv_mode alphabet above 32x32

Browse files at this commit

e4259c9cd04a47558e32c7914fe5ef32ed7d35bfAhmet Kaan GümüşParent: e4febc9
  • fix
    • an intra block in an INTER frame reads the no-CFL uv_mode alphabet above 32x32
Show full message
fix(av1): an intra block in an INTER frame reads the no-CFL uv_mode alphabet above 32x32

libaom `read_intra_block_mode_info` calls
`read_intra_mode_uv(ec_ctx, r, is_cfl_allowed(xd), bsize)`, and
`is_cfl_allowed` (blockd.h) is
`block_size_wide[bsize] <= 32 && block_size_high[bsize] <= 32`.
`decode_inter_block`'s intra tail read the 14-symbol `uv_mode_cfl` CDF
unconditionally, so every intra block 64 px or wider inside an inter frame
decoded the same VALUE off a different interval and desynced the tile at
that symbol (class wrong-alphabet-same-value). Every other `uv_mode` reader
in this file already makes the split; this was the last one.

Found by an aomdec-vs-ours msac RANGE ladder on a 256x256 --sb-size=128
8-frame aomenc stream: the 64x64 intra block at mi (0,32) of an inter frame
entered at rng=61470 in both decoders and left at 35887 (ours) vs 54271
(aomdec), 4 bits over-read; after the fix the whole ladder tracks.

Also: the partition_w64 trace line carries its pre-read range and the
EC_MODE line carries is_inter/skip/side, both behind the existing env vars.
crates/ec-av1/src/decode.rsmodified+17 -3
@@ -16399,10 +16399,12 @@ fn decode_inter_block(
16399 }16399 }
16400 if std::env::var_os("EC_TRACE_MODE").is_some() {16400 if std::env::var_os("EC_TRACE_MODE").is_some() {
16401 eprintln!(16401 eprintln!(
16402- "EC_MODE mi_row={} mi_col={} rng={}",16402+ "EC_MODE mi_row={} mi_col={} rng={} is_inter={} skip={} side={side}",
16403 rmi,16403 rmi,
16404 cmi,16404 cmi,
16405- dec.debug_state().016405+ dec.debug_state().0,
16406+ u8::from(is_inter),
16407+ u8::from(skip)
16406 );16408 );
16407 }16409 }
16408 // lane-warp r5: see `reject_residual` -- a square-block decode of a16410 // lane-warp r5: see `reject_residual` -- a square-block decode of a
@@ -18707,7 +18709,19 @@ fn decode_inter_block(
18707 // directional intra-in-inter block was refused above.18709 // directional intra-in-inter block was refused above.
18708 let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);18710 let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
18709 let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);18711 let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
18710- let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]);18712+ // lane-sb128c r2: libaom `read_intra_mode_uv(ec_ctx, r, is_cfl_allowed(xd), bsize)`
18713+ // -- `is_cfl_allowed` (blockd.h:1298) is
18714+ // `block_size_wide[bsize] <= 32 && block_size_high[bsize] <= 32`, so a
18715+ // 64x64 (or 64-wide/high) intra block inside an INTER frame reads the
18716+ // 13-symbol `uv_mode_no_cfl` alphabet. Reading the 14-symbol CFL one
18717+ // gives the same VALUE but a different range, and desynced the tile at
18718+ // this symbol (class wrong-alphabet-same-value).
18719+ let cfl_allowed = write_w.max(write_h) <= 32;
18720+ let uv_mode = if cfl_allowed {
18721+ dec.symbol(&mut cdfs.uv_mode_cfl[mode])
18722+ } else {
18723+ dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
18724+ };
18711 if (9..=12).contains(&uv_mode) {18725 if (9..=12).contains(&uv_mode) {
18712 SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));18726 SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));
18713 }18727 }
crates/ec-av1/src/stream.rsmodified+4 -1
@@ -18391,7 +18391,10 @@ mod tests {
18391 // transform unit is 32x64" -- an intra rect strip aomenc cannot have coded18391 // transform unit is 32x64" -- an intra rect strip aomenc cannot have coded
18392 // with `--enable-rect-partitions=0`, so our own 128 inter block desyncs18392 // with `--enable-rect-partitions=0`, so our own 128 inter block desyncs
18393 // first (class refusal-from-own-desync). r2 owns the range ladder.18393 // first (class refusal-from-own-desync). r2 owns the range ladder.
18394- #[ignore = "lane-sb128c r1: the 128 inter NONE block still desyncs; see lanes/sb128c-r1.report.md"]18394+ #[ignore = "lane-sb128c r2: the 128 inter NONE block is now in sync (the uv_mode alphabet fix); \
18395+ this stream also carries ONE intra-coded 128x128 block inside an inter frame \
18396+ (aomdec EC_PART_VAL mi_row=32 mi_col=32 bsize=15 value=0 with no EC_MODE), which \
18397+ is still refused by name -- see lanes/sb128c-r2.report.md"]
18395 fn a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact() {18398 fn a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact() {
18396 const NAME: &str = "a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact";18399 const NAME: &str = "a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact";
18397 let _gate_lock = lock_gate_counters();18400 let _gate_lock = lock_gate_counters();