forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

svtinter.report.md7.2 KiBHistoryRawDownload

lane-svtinter — the palette colour-index map read past the frame edge

Class: map-read-past-frame-edge — a syntax loop whose extent the spec clamps to the block's ON-SCREEN part, read at the full block size, so the decoder consumes symbols the encoder never wrote.

First divergent symbol

Stream smptebars=s=384x152:r=12,drawgrid=w=8:h=8:t=1:c=black through libsvtav1 -preset 8 -crf 30 -svtav1-params lp=1:screen-content-mode=1, frame 0 (the KEY frame — the defect is not inter-only; lane-svt1's "key frames are exact" held only for its own kept stream).

  • Pixels: first wrong luma sample at row 128, col 296; everything after it in the raster diverges (1599 luma + 28 chroma in frame 0, ~80k per inter frame).
  • Partitions agree with an instrumented aomdec (EC_TRACE) through the whole frame up to mi_row=32 mi_col=72 bsize=BLOCK_32X32 PARTITION_NONE, which is exactly the block covering pixel (128, 288).
  • Mode ladder agrees symbol for symbol into that block (EC_TRACE_MODE_STEP, EC_PALSYN): skip=1, y_mode=DC, uv_mode=DC, palette_y_mode=1, palette_y_size=3, colours [7,16,24], rng=39432 on both sides.
  • First divergent symbol: the colour-index map's wavefront, diagonal i = 24. aomdec's last symbol on that diagonal is row=23 col=1 and it moves on to row=0 col=25; ours reads one more, row=24 col=0, and every symbol after that is one position out of step (rng 42060 vs 42068 from there on).

Root cause

The block is 32x32 at mi row 32 of a 38-mi-tall frame: only 24 of its 32 rows are inside the mi grid. Spec 5.11.50 palette_tokens / av1_get_block_dimensions (blockd.h:1512) read the colour-index map over onscreenWidth x onscreenHeight only and REPLICATE the last on-screen column and row over the rest (detokenize.c:71). decode_color_index_map_wh walked the full bw x bh grid — its own doc comment asserted the clamp was unnecessary ("palette blocks ... never straddle the frame's true edge").

Both reported failure kinds are this one defect: the extra symbols either shift the rest of the tile (~200k-sample misses) or eventually make a coeff Golomb tail read as absurdly long ("a Golomb tail longer than this decoder reads" — a desync symptom, never a reader bound, as the standing class says).

Fix

crates/ec-av1/src/decode.rs:

  • palette_onscreen(mi_r, mi_c, bw, bh, fctx) — the on-screen extent in luma pixels, from fctx.seg_mi_dims (set once per frame for every frame).
  • palette_onscreen_uv(luma, on, chroma) — the same carried into chroma, keeping the is_chroma_sub8 +2 bump in step with the caller's own (bw / 2).max(4).
  • decode_color_index_map{,_wh} take (onscreenWidth, onscreenHeight), read the wavefront over that corner at the full-block stride, then replicate the last on-screen column and row (libaom's own two extension loops).
  • A second commit (fe850816's successor) restricts the clamp to contexts where the frame's mi dims are known: the ENCODER's own in-process reconstruct runs on a FrameCtx::for_encoder that never saw set_segmentation, so its dims are (0, 0) and the first version read every map as 1x1 there -- 16 round-trip gates (10 in s1, 6 in s2) refused with a bogus "a reference frame selected with no picture at this frame's own ref_frame_idx slot" (verified NOT pre-existing: the same 10 tests pass on base 5e14d407, $HOME/.cache/svtinter/sub-base.log). That path's writer half is unclamped too, so the two mirror each other; the branch carries a corner-cut: comment naming the ceiling (see Open).

Same-shape sweep (class: a per-cell map read over a block that straddles

the frame edge)

Reader call sites of the fixed function — all five take the clamp: key-frame square (read_intra_mode), rect strip (read_intra_mode_rect), intra-in-inter rect (decode_intra_rect_in_inter), inter block intra (decode_inter_block), 8x8 inter leaf (decode_inter_block8), luma and chroma each.

Every OTHER syntax family whose symbol COUNT is clipped by the mi grid was checked and already carries its clip — this was the last unclipped one:

family site state
residual transform units, luma decode.rs:9546 if tu_px >= y.true_width || tu_py >= y.true_height clipped (lane-hgkf)
residual transform units, chroma decode.rs:24773, 24881 (max_blocks_wide/high) clipped
var-tx recursion decode.rs:17745 if blk_row >= max_h_mi || blk_col >= max_w_mi clipped
segment ids decode.rs:989, 1012 (x_mis/y_mis) clipped
partition hasRows/hasCols inferred split clipped
palette colour-index map decode.rs decode_color_index_map_wh fixed here

CfL and intrabc read no per-cell map (CfL is one alpha pair per block, intrabc one vector), so neither can spend symbols past the edge.

Pass table

Every decode compares EVERY plane of EVERY frame against ffmpeg -pix_fmt yuv420p (harness asserts our decode exited 0 and produced N frames first).

streams before after
fresh sweep: smptebars,drawgrid x {384x152, 320x184, 640x366} x crf {20,30,35,45}, 4 frames 8 exact, 2 DIFF (22397/1599 samples in frame 0 alone), 3 REFUSED (Golomb tail) — 12 total 12/12 exact
kept $HOME/.cache/svt1-keep/w3/*.obu (180 streams) (lane-svt1: 2 refusals + 6 x ~200k-sample misses among the 8 that reach its arm) 180/180 exact

No refusal string survives on any stream in either set.

Witness

stream::tests::an_svt_screen_palette_map_cut_by_the_frame_edge_decodes_exactly BUILDS its stream in-test (the recipe above at crf 30), SKIPs with a printed reason when ffmpeg/libsvtav1 is missing, asserts the new decode::palette_onscreen_cut_hits() counter is non-zero (so it cannot pass on a stream that never cuts a palette map) and compares all three planes of all four frames against ffmpeg.

  • RED (reader reverted to the full-grid walk, counter kept): test result: FAILED. 0 passed; 1 failed, panic frame 0 luma vs ffmpeg.
  • GREEN: test result: ok. 1 passed.

Open

  • open| The WRITE side has the same shape: tile.rs:3457 write_color_index_map walks side x side with no on-screen clamp (callers at 3498 / 3908 / 3913). Reachable only when our own encoder codes a palette block straddling the mi grid (screen-content mode at a frame size whose bottom/right block is cut) — not fixed here because a writer change moves the encoder pins, which this lane must leave byte-identical.

Gates on 58b83958

gate result
cargo check --workspace --all-targets -j4 RC=0, 0 ec-av1 warnings (25 pre-existing missing documentation warnings, all in ec-opus)
encode::tests::the_encoders_own_streams_are_byte_identical_to_their_pins ok, 1 passed — pins unchanged
the new witness ok, 1 passed
kept-film SVT gate (EC_AV1_SVT1_STREAM, an_svt_screen_palette_block_with_a_split_transform_decodes_exactly) ok, 1 passed
s1 --skip stream:: ok, 341 passed, 0 failed, 33 ignored (389 s)
s2 stream:: --skip 10bit ok, 202 passed, 0 failed, 15 ignored (607 s)
s3 10bit ok, 42 passed, 0 failed, 1 ignored (43 s)
180 kept w3 streams vs ffmpeg 180/180 exact
fresh sweep (12 streams) vs ffmpeg 12/12 exact

The first fix alone (f70ec3f9) reddened 16 of these rows; both suites are green only with 58b83958 on top.