forge
Explore
Log in

Don't you dare go Hollow

Three more refusals proven -- empty tile group, empty show_existing slot, key-less inter frame

Browse files at this commit

2eab33d85eb510ca0912082d33a9f264ac971d37Ahmet Kaan GümüşParent: ff81ea8
  • test
    • three more refusals proven -- empty tile group, empty show_existing slot, key-less inter frame
Show full message
test(av1): three more refusals proven -- empty tile group, empty show_existing slot, key-less inter frame

* "a frame OBU with no tile group" -- ENUMERATION. `parse_tile_group` is the
  only producer of the `tiles` vector `decode_stream` tests, and its success
  path pushes one `Tile` per member of the inclusive range `tg_start..=tg_end`,
  which is never empty. A real frame OBU's tile payload truncated from empty
  upwards confirms it: every OBU that parses carries a tile, and none of them
  reaches the refusal. An empty payload parses into ONE zero-byte tile, not
  none, which is why the charter's "payload ends after the frame header"
  fixture cannot reach the string.
* "a show_existing_frame header naming an empty reference slot" -- NEGATIVE
  GATE over all 8 slots. The header OBU is hand-written (spec 5.9.2 codes only
  show_existing_frame + frame_to_show_map_idx here) because the frame header
  writer writes shown key/inter frames only. A shown key frame refreshes every
  slot, so a stream that opens on this header is the only reachable shape --
  the charter's "key frame with the bit clear" cannot be written.
* "an inter frame with no key frame before it" -- NEGATIVE GATE, built from
  this crate's own writers (a shown inter frame is writable) instead of a
  stripped aomenc stream: no external tool, byte-identical every run.

Both gates assert the refusal by name AND that the sink saw no picture.
crates/ec-av1/src/refusal_inventory.rsmodified+19 -0
@@ -262,6 +262,25 @@ const PROVEN: &[(&str, &str)] = &[
262262 "a Golomb tail longer than this decoder reads",
263263 "read_golomb_reads_every_value_a_conformant_stream_can_carry",
264264 ),
265+ // lane-t900 r25, enumeration: `parse_tile_group` is the only producer of
266+ // the `tiles` vector `decode_stream` tests, and its success path always
267+ // pushes at least one `Tile` -- swept over a real frame OBU's tile payload
268+ // truncated from empty upwards.
269+ (
270+ "a frame OBU with no tile group",
271+ "a_frame_obu_that_parses_always_carries_at_least_one_tile",
272+ ),
273+ // lane-t900 r25, negative gates: hand-built streams that reach each
274+ // refusal by name and output no picture (a `show_existing_frame` header
275+ // over all 8 empty slots; a stream that opens on an inter frame).
276+ (
277+ "a show_existing_frame header naming an empty reference slot",
278+ "a_show_existing_frame_header_naming_an_empty_slot_is_refused_by_name",
279+ ),
280+ (
281+ "an inter frame with no key frame before it",
282+ "an_inter_frame_opening_a_stream_is_refused_by_name",
283+ ),
265284 // lane-t900 r25, enumeration: a motion_mode/obmc symbol is read only under
266285 // `is_motion_variation_allowed_bsize` (min side >= 8), and each of the 17
267286 // `BLOCK_SIZES_ALL` footprints that clause admits maps to a distinct row of
crates/ec-av1/src/stream.rsmodified+156 -0
@@ -1168,6 +1168,162 @@ mod tests {
11681168 );
11691169 }
11701170
1171+ /// lane-t900 r25: the refusal "a frame OBU with no tile group" names a
1172+ /// shape the parser cannot hand [`decode_stream`].
1173+ ///
1174+ /// `tiles` reaches that check from exactly two places -- `ObuKind::Frame`'s
1175+ /// own vector and the `ObuKind::TileGroup` accumulation -- and both are
1176+ /// filled by `ec_av1_syntax`'s `parse_tile_group`, whose only success path
1177+ /// pushes one `Tile` per `tile_num` of the INCLUSIVE range
1178+ /// `tg_start..=tg_end`. That range is never empty: the single-tile-group
1179+ /// case takes `(0, num_tiles - 1)` saturating at 0, and the multi-group
1180+ /// case rejects `end < start` as corrupt. So an `OBU_FRAME` either fails to
1181+ /// parse or carries at least one tile, however short its payload is --
1182+ /// including the empty payload the charter for this round asked to build,
1183+ /// which parses into ONE zero-byte tile rather than none.
1184+ ///
1185+ /// Sweeping a real frame OBU's tile payload from empty upwards asserts both
1186+ /// halves: every `Frame` OBU that parses has a tile, and `decode_stream`
1187+ /// never reports this refusal for any of them.
1188+ #[test]
1189+ fn a_frame_obu_that_parses_always_carries_at_least_one_tile() {
1190+ const REFUSAL: &str = "a frame OBU with no tile group";
1191+ let picture = test_card(64, 64);
1192+ let encoded = encode_key_frame(&picture, 100, 0.5).unwrap();
1193+ let (seq, header) = crate::encode::key_frame_headers(64, 64, 100).unwrap();
1194+ let mut frame_obus_parsed = 0;
1195+ for len in 0..=encoded.tile.len().min(24) {
1196+ let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap();
1197+ stream.extend_from_slice(
1198+ &crate::frame::frame_obu(&seq, &header, &encoded.tile[..len]).unwrap(),
1199+ );
1200+ let mut parser = Av1Parser::new();
1201+ let mut pos = 0usize;
1202+ while pos < stream.len() {
1203+ let Ok(obu) = parser.parse_obu(&stream[pos..]) else {
1204+ break;
1205+ };
1206+ pos += obu.total_size;
1207+ if let ObuKind::Frame(_, tiles) = &obu.kind {
1208+ frame_obus_parsed += 1;
1209+ assert!(
1210+ !tiles.is_empty(),
1211+ "a {len}-byte tile payload parsed into a frame OBU with no tile group -- \
1212+ the refusal {REFUSAL:?} is reachable after all"
1213+ );
1214+ }
1215+ }
1216+ if let Err(e) = decode_stream(&stream) {
1217+ let e = e.to_string();
1218+ assert!(
1219+ !e.contains(REFUSAL),
1220+ "a {len}-byte tile payload reached {REFUSAL:?}: {e}"
1221+ );
1222+ }
1223+ }
1224+ assert!(
1225+ frame_obus_parsed >= 2,
1226+ "the sweep parsed {frame_obus_parsed} frame OBUs -- it proves nothing about the \
1227+ refusal's reachability"
1228+ );
1229+ }
1230+
1231+ /// lane-t900 r25, negative gate: a `show_existing_frame` header naming a
1232+ /// slot no frame has refreshed is refused BY NAME, and outputs no picture.
1233+ ///
1234+ /// The OBU is hand-built because [`crate::frame::write_frame_header`]
1235+ /// refuses to write one (it writes shown key and inter frames only): spec
1236+ /// 5.9.2's whole header for this case is `show_existing_frame` (1) plus
1237+ /// `frame_to_show_map_idx` (3), the sequence carrying neither a decoder
1238+ /// model nor frame ids.
1239+ ///
1240+ /// Deviation from the round's charter, which asked for a key frame first
1241+ /// with the named slot's `refresh_frame_flags` bit clear: a SHOWN key frame
1242+ /// refreshes every slot (spec 5.9.2 forces `refresh_frame_flags` to
1243+ /// `all_frames` and does not code it, which is also what
1244+ /// `write_frame_header` does), so the only reachable empty-slot stream is
1245+ /// one where no frame has refreshed that slot yet. The stream below is a
1246+ /// valid sequence header followed by the header OBU, and every one of the
1247+ /// eight slots is tried.
1248+ #[test]
1249+ fn a_show_existing_frame_header_naming_an_empty_slot_is_refused_by_name() {
1250+ const REFUSAL: &str = "a show_existing_frame header naming an empty reference slot";
1251+ let (seq, _) = crate::encode::key_frame_headers(64, 64, 100).unwrap();
1252+ for slot in 0..NUM_REF_FRAMES as u32 {
1253+ let mut w = ec_core::BitWriter::new();
1254+ w.write_bit(true); // show_existing_frame
1255+ w.write_bits(slot, 3); // frame_to_show_map_idx
1256+ crate::bits::write_byte_alignment(&mut w);
1257+ let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap();
1258+ stream.extend_from_slice(&crate::obu::wrap_obu(
1259+ &ec_av1_syntax::obu::ObuHeader {
1260+ obu_type: ec_av1_syntax::obu::ObuType::FrameHeader,
1261+ extension_flag: false,
1262+ has_size_field: true,
1263+ temporal_id: 0,
1264+ spatial_id: 0,
1265+ },
1266+ &w.into_bytes(),
1267+ ));
1268+
1269+ let mut shown = 0;
1270+ let err = decode_stream_with(&stream, |_, _, _| {
1271+ shown += 1;
1272+ Ok(())
1273+ })
1274+ .unwrap_err()
1275+ .to_string();
1276+ assert!(
1277+ err.contains(REFUSAL),
1278+ "slot {slot}: expected {REFUSAL:?}, got: {err}"
1279+ );
1280+ assert_eq!(shown, 0, "slot {slot}: an empty slot was output as a picture");
1281+ }
1282+ }
1283+
1284+ /// lane-t900 r25, negative gate: an inter frame whose `ref_frame_idx[0]`
1285+ /// slot holds no picture -- a stream that opens on an inter frame -- is
1286+ /// refused BY NAME rather than predicting from nothing.
1287+ ///
1288+ /// Deviation from the round's charter, which asked for a real aomenc
1289+ /// two-frame stream with the key frame's OBUs stripped: this crate's own
1290+ /// `write_frame_header` writes a shown INTER frame (short reference
1291+ /// signalling and non-identity global motion are the parts it refuses), so
1292+ /// the fixture is built from the writers, needs neither ffmpeg nor aomenc,
1293+ /// and is byte-identical on every run. The tile payload is a real key
1294+ /// frame's; the refusal fires on the header's reference lookup, before any
1295+ /// tile is decoded.
1296+ #[test]
1297+ fn an_inter_frame_opening_a_stream_is_refused_by_name() {
1298+ const REFUSAL: &str = "an inter frame with no key frame before it";
1299+ let picture = test_card(64, 64);
1300+ let encoded = encode_key_frame(&picture, 100, 0.5).unwrap();
1301+ let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap();
1302+ let inter = FrameHeader {
1303+ frame_type: FrameType::Inter,
1304+ frame_is_intra: false,
1305+ // Keeps `primary_ref_frame`, `frame_size_with_refs` and
1306+ // `use_ref_frame_mvs` out of the written header (spec 5.9.2).
1307+ error_resilient_mode: true,
1308+ primary_ref_frame: PRIMARY_REF_NONE,
1309+ refresh_frame_flags: 0x02,
1310+ order_hint: 1,
1311+ ..key
1312+ };
1313+ let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap();
1314+ stream.extend_from_slice(&crate::frame::frame_obu(&seq, &inter, &encoded.tile).unwrap());
1315+
1316+ let mut shown = 0;
1317+ let err = decode_stream_with(&stream, |_, _, _| {
1318+ shown += 1;
1319+ Ok(())
1320+ })
1321+ .unwrap_err()
1322+ .to_string();
1323+ assert!(err.contains(REFUSAL), "expected {REFUSAL:?}, got: {err}");
1324+ assert_eq!(shown, 0, "an inter frame with no reference produced a picture");
1325+ }
1326+
11711327 /// lane-interedge r1: one attempt of the inter frame-edge half-strip gate --
11721328 /// encode `width x height` with real aomenc (rect partitions ON, every other
11731329 /// lane's open tool pinned off), decode it, and return