forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-bd12': bit_depth 12 refused by name in decode_stream (warp/MC/wiener shifts change at 12-bit; no 12-bit gate), reachability test

Browse files at this commit

3281246281311738bafbfbec5d0efd8e150eba20Ahmet Kaan GümüşParent: b933555efb4f45
crates/ec-av1/src/refusal_inventory.rsmodified+1 -0
@@ -52,6 +52,7 @@ const REFUSALS: &[&str] = &[
52 "a block that actually uses a palette (UV) -- reconstruction is out of scope",52 "a block that actually uses a palette (UV) -- reconstruction is out of scope",
53 "a block that actually uses a palette (Y) -- reconstruction is out of scope",53 "a block that actually uses a palette (Y) -- reconstruction is out of scope",
54 "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)",54 "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)",
55+ "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",
55 "a frame OBU with no tile group",56 "a frame OBU with no tile group",
56 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",57 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",
57 "a frame with no mode-info grid",58 "a frame with no mode-info grid",
crates/ec-av1/src/stream.rsmodified+45 -0
@@ -461,6 +461,19 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
461 let bit_depth = parser461 let bit_depth = parser
462 .sequence_header()462 .sequence_header()
463 .map_or(8, |seq| seq.color_config.bit_depth);463 .map_or(8, |seq| seq.color_config.bit_depth);
464+ // lane-bd12: the sequence-header parser accepts `twelve_bit`, but every
465+ // rounding shift below is written for 8/10-bit only -- `warp.rs`'s
466+ // `REDUCE_BITS_HORIZ` is a hard 3 where libaom uses
467+ // `round_0 + max(bd + FILTER_BITS - round_0 - 14, 0)` (5 at bd 12), the
468+ // MC `round_0`/`round_1` change at 12-bit (libaom convolve.h:83), the
469+ // Wiener rounding bits change, and neither CDEF nor film grain has a
470+ // 12-bit path. Refuse by name rather than decode silently wrong pixels.
471+ if bit_depth == 12 {
472+ return Err(Error::unsupported(
473+ "AV1 decode_stream",
474+ "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",
475+ ));
476+ }
464 crate::decode::set_bit_depth(bit_depth);477 crate::decode::set_bit_depth(bit_depth);
465 // lane-av1comp: `comp_group_idx`/`compound_idx`'s own gating bits.478 // lane-av1comp: `comp_group_idx`/`compound_idx`'s own gating bits.
466 let enable_masked_compound = parser479 let enable_masked_compound = parser
@@ -799,6 +812,38 @@ mod tests {
799 picture812 picture
800 }813 }
801 814
815+ /// A stream whose sequence header says `twelve_bit` is refused by name
816+ /// rather than decoded with the 8/10-bit rounding shifts (`warp.rs`'s
817+ /// hard `REDUCE_BITS_HORIZ = 3`, MC/Wiener round bits, ungated CDEF and
818+ /// film grain). Reachability, not a pixel claim: the header is written at
819+ /// `seq_profile = 2` so `twelve_bit` is actually coded, and the frame's
820+ /// tile payload is never reached.
821+ #[test]
822+ fn a_twelve_bit_sequence_header_is_refused_by_name() {
823+ let picture = test_card(64, 64);
824+ let encoded = encode_key_frame(&picture, 100, 0.5).unwrap();
825+ let mut color = ec_av1_syntax::ColorConfig {
826+ bit_depth: 12,
827+ ..Default::default()
828+ };
829+ color.num_planes = 3;
830+ // Only seq_profile 2 codes the `twelve_bit` bit (spec 5.5.2).
831+ let (mut seq, header) =
832+ crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap();
833+ seq.seq_profile = 2;
834+ let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap();
835+ stream.extend_from_slice(&crate::frame::frame_obu(&seq, &header, &encoded.tile).unwrap());
836+
837+ let err = decode_stream(&stream).unwrap_err().to_string();
838+ assert!(
839+ err.contains(
840+ "a bit depth of 12 (this decoder is gated at 8 and 10 only: \
841+ warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)"
842+ ),
843+ "expected the 12-bit refusal, got: {err}"
844+ );
845+ }
846+
802 /// `decode_stream` on a lone key frame's stream matches both the tile847 /// `decode_stream` on a lone key frame's stream matches both the tile
803 /// path (`decode_key_frame_tile` called directly on `Encoded::tile`) and848 /// path (`decode_key_frame_tile` called directly on `Encoded::tile`) and
804 /// the encoder's own reconstruction, at an even and an odd size.849 /// the encoder's own reconstruction, at an even and an odd size.