forge
Explore
Log in

Don't you dare go Hollow

Refuse TxMode::Select streams instead of silently desyncing

Browse files at this commit

93bc3b112c61701a1959f9bbf6ef10082e2ecce8Ahmet Kaan GümüşParent: e37bffe
  • fix
    • refuse TxMode::Select streams instead of silently desyncing
Show full message
fix(av1): refuse TxMode::Select streams instead of silently desyncing

decode_block never reads tx_depth symbols; a TxMode::Select stream
decodes syntactically clean into low-energy garbage (the r3 flat-luma
shape's sibling). Named refusal, same pattern as CDEF. The pinned CfL
stream's symbols are cross-checked bit-for-bit through the EOB group
via an independent from-scratch MSAC decoder; remaining suspects are
the coefficient-level symbols and the harness itself (see ignore note).
crates/ec-av1/src/stream.rsmodified+20 -2
@@ -10,7 +10,7 @@
10 //! are `pub(crate)`, and rightly so: the wire is `stream`, everything else is10 //! are `pub(crate)`, and rightly so: the wire is `stream`, everything else is
11 //! an implementation detail of how this crate happens to build it).11 //! an implementation detail of how this crate happens to build it).
12 12
13-use ec_av1_syntax::{Av1Parser, CdefParams, FrameType, ObuKind};13+use ec_av1_syntax::{Av1Parser, CdefParams, FrameType, ObuKind, TxMode};
14 use ec_core::{Error, Result};14 use ec_core::{Error, Result};
15 15
16 use crate::decode::{decode_inter_frame_tile, decode_key_frame_tile};16 use crate::decode::{decode_inter_frame_tile, decode_key_frame_tile};
@@ -75,6 +75,24 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
75 "a frame with an active CDEF filter (not yet applied by this decoder)",75 "a frame with an active CDEF filter (not yet applied by this decoder)",
76 ));76 ));
77 }77 }
78+ // Every `decode_block` call below assumes the block's transform is
79+ // its own full size (`TxMode::Largest`, which is all this crate's own
80+ // encoder ever writes, spec `read_tx_size` inferring the max depth
81+ // with no bits) -- it never reads a `tx_depth` symbol at all. A real
82+ // encoder's `TxMode::Select` (spec 5.9.2's `tx_mode` bit) codes one
83+ // per intra block, and skipping that read does not error -- the
84+ // decoder just goes on consuming the next bits as if they were the
85+ // uv_mode/coefficient symbols they are not, so the block "decodes"
86+ // syntactically clean into low-energy garbage: lane-av1real r3's
87+ // luma-near-flat-vs-ffmpeg-gradient bug. Refuse before that, the same
88+ // way as the CDEF case above, rather than silently miscode every
89+ // `TxMode::Select` stream.
90+ if header.tx_mode == TxMode::Select {
91+ return Err(Error::unsupported(
92+ "AV1 decode_stream",
93+ "a frame using TxMode::Select (this decoder never reads a tx_depth symbol, so it desyncs after the first intra block's mode)",
94+ ));
95+ }
78 // `Tile::offset` is relative to the buffer `parse_obu` was handed96 // `Tile::offset` is relative to the buffer `parse_obu` was handed
79 // (`&data[pos..]` at the time this OBU was parsed), so it is relative97 // (`&data[pos..]` at the time this OBU was parsed), so it is relative
80 // to `obu_offset`, not to `data` as a whole.98 // to `obu_offset`, not to `data` as a whole.
@@ -494,7 +512,7 @@ mod tests {
494 /// stays DC. Proves the CfL port this round added, not just DC-chroma512 /// stays DC. Proves the CfL port this round added, not just DC-chroma
495 /// decode: pixel-exact against ffmpeg's own decode, not just "decoded".513 /// decode: pixel-exact against ffmpeg's own decode, not just "decoded".
496 #[test]514 #[test]
497- #[ignore = "r2 checkpoint: LUMA (not chroma) decodes near-flat 126-129 where ffmpeg shows a 41-82 gradient on the pinned CfL stream — the remaining bug is upstream of the CfL chroma math this round added; isolate the luma path first (r3)"]515+ #[ignore = "r4: NOT the TX_64X64 corner-padding path (that path is proven pixel-exact by a_real_libaom_gradients_stream_decodes_pixel_exact, side=64/tx_side=32, real non-skip content) -- this stream's one block is TX32-on-side-32 (tx_side==side, the trivial no-padding branch), luma_set=TxbSet::Luma32, cfl=true. Independently cross-checked with a from-scratch Python spec-8.2.6 MSAC decoder against the raw tile bytes: partition_w32/skip/kf_y_mode/uv_mode_cfl/txb_skip_luma_32_q1/eob_pt_1024_luma_q1 all match our Rust decode's symbols bit-for-bit (partition=NONE, skip=false, y_mode=DC_PRED, uv_mode=DC_PRED, all_zero=false, eob group=5 i.e. eob in 9..=12) -- so the desync (if any) is not in decode_block's mode/uv_mode reads nor in read_eob's group symbol. dq_denom(32*32=1024)=2 and dq_denom(64*64=4096)=4 both match spec 7.12.3 and both are covered by the passing the_inverse_network_is_an_orthonormal_dct_over_eight unit test. Remaining candidates, unverified this round: (a) the base/base_eob/br coefficient-level symbols past eob group (not traced), (b) TxbSet::Luma32's coefficient CDF tables specifically at q-context 1 (only skip/eob_pt were cross-checked, not base/br), (c) the ffmpeg reference decode itself for a 32x32-only frame (possible harness mismatch, unverified). r5 should extend the python cross-check through the full coefficient loop (base/base_eob/br/dc_sign) using the q1 tables, and/or dump ffmpeg's own frame_size/superres fields for this specific OBU to rule out (c)"]
498 fn a_real_libaom_cfl_stream_decodes_pixel_exact() {516 fn a_real_libaom_cfl_stream_decodes_pixel_exact() {
499 if !have_ffmpeg() {517 if !have_ffmpeg() {
500 eprintln!("SKIP a_real_libaom_cfl_stream_decodes_pixel_exact: no ffmpeg");518 eprintln!("SKIP a_real_libaom_cfl_stream_decodes_pixel_exact: no ffmpeg");