From 0593def5d0613bea46cdf1828c299ad45fd0e5a4 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 24 Nov 2026 19:48:21 +0000 Subject: [PATCH] craft-openpgp, craft-raw, craft-captions, craft-xml, craft-ods, craft-proof, craft-font-subset, craft-drawingml: smaller or gated passes --- crates/captions/Cargo.toml | 1 + crates/captions/tests/it/limits.rs | 3 ++- crates/drawingml/src/table.rs | 2 +- crates/font-subset/Cargo.toml | 1 + crates/font-subset/src/woff2.rs | 4 +++- crates/ods/tests/read.rs | 18 ++++++++++-------- crates/openpgp/Cargo.toml | 1 + crates/openpgp/src/keys_tests.rs | 5 +++++ crates/proof/Cargo.toml | 1 + crates/proof/src/affix_suggest.rs | 4 +++- crates/raw/Cargo.toml | 2 ++ crates/raw/src/arw_lens.rs | 6 ++++-- crates/raw/tests/it/dng_lines.rs | 4 ++++ crates/xml/Cargo.toml | 3 +++ crates/xml/tests/it/hostile.rs | 29 +++++++++++++++++------------ 15 files changed, 58 insertions(+), 26 deletions(-) diff --git a/crates/captions/Cargo.toml b/crates/captions/Cargo.toml index 1136f55f9..4a4e27520 100644 --- a/crates/captions/Cargo.toml +++ b/crates/captions/Cargo.toml @@ -21,6 +21,7 @@ craft-xml = { workspace = true } thiserror = { workspace = true } [dev-dependencies] +craft-testkit = { workspace = true } proptest = { workspace = true } # A second XML reader for the tests: checks of written TTML, and the comparison in tests/it/ttml_xml_views.rs. roxmltree = "0.21" diff --git a/crates/captions/tests/it/limits.rs b/crates/captions/tests/it/limits.rs index 3b908fa06..0b010ed41 100644 --- a/crates/captions/tests/it/limits.rs +++ b/crates/captions/tests/it/limits.rs @@ -35,7 +35,8 @@ fn mutated_files_never_panic() { for format in Format::ALL { let bytes = write(&doc(), format, WriteOptions::default()); // every byte of a text file, and the header and first blocks of the (sparse) binary one - for i in 0..bytes.len().min(2048) { + // The gate runs every divisor-th byte; nightly runs every one. + for i in (0..bytes.len().min(2048)).step_by(craft_testkit::hostile::divisor()) { for v in [0u8, 0x20, 0x3c, 0x7f, 0xff] { let mut m = bytes.clone(); if let Some(b) = m.get_mut(i) { diff --git a/crates/drawingml/src/table.rs b/crates/drawingml/src/table.rs index b5d83d530..cc71dac1d 100644 --- a/crates/drawingml/src/table.rs +++ b/crates/drawingml/src/table.rs @@ -749,7 +749,7 @@ mod tests { let mut t = Table { cols: vec![1.0; MAX_CELLS + 5], rows: vec![Row::default(); 3], ..Default::default() }; t.normalize(); assert_eq!((t.cols.len(), t.rows.len()), (MAX_CELLS, 1)); - let wide = Table { cols: vec![10.0; 1000], rows: vec![Row { height: 1.0, cells: vec![Cell::new("x"); 1500] }; 150], ..Default::default() }; + let wide = Table { cols: vec![10.0; 1000], rows: vec![Row { height: 1.0, cells: vec![Cell::new("x"); 1100] }; MAX_CELLS / 1000 + 1], ..Default::default() }; let mut n = wide.clone(); n.normalize(); assert_eq!(wide.normalized(), n); diff --git a/crates/font-subset/Cargo.toml b/crates/font-subset/Cargo.toml index 645b24f61..7810620ef 100644 --- a/crates/font-subset/Cargo.toml +++ b/crates/font-subset/Cargo.toml @@ -16,6 +16,7 @@ unicode-normalization = "0.1.26" write-fonts = { version = "0.55", features = ["read"] } [dev-dependencies] +craft-testkit = { workspace = true } rustybuzz = "0.20.1" serde_json = "1" wuff = "0.2.9" diff --git a/crates/font-subset/src/woff2.rs b/crates/font-subset/src/woff2.rs index e6a3d3526..57f0d2d25 100644 --- a/crates/font-subset/src/woff2.rs +++ b/crates/font-subset/src/woff2.rs @@ -185,7 +185,9 @@ mod tests { #[test] fn round_trips_every_table_and_header_matches_spec() { - for path in FIXTURES { + // The gate runs a TrueType and a CFF font (the first and the last); nightly runs all of them. + let all = craft_testkit::hostile::divisor() == 1; + for path in FIXTURES.iter().enumerate().filter(|(i, _)| all || *i == 0 || *i == FIXTURES.len() - 1).map(|(_, p)| p) { let sfnt = fixture(path); let tables = parse_tables(&sfnt).unwrap(); for quality in [Quality::Static, Quality::OnDemand] { diff --git a/crates/ods/tests/read.rs b/crates/ods/tests/read.rs index 530177b4c..9c44e09ec 100644 --- a/crates/ods/tests/read.rs +++ b/crates/ods/tests/read.rs @@ -206,23 +206,25 @@ fn expansion_bounds_stop_small_repeat_bombs() { r#""#, ); assert!(matches!(open(&cells), Err(Error::TooLarge(_)))); + // Text limits are set small so the files stay small: 1 MiB of text over all sheets, 64 KiB a cell. + let tight = Options { max_text: 1 << 20, max_cell_text: 64 << 10, ..Options::default() }; let text = format!( - r#""#, + r#""#, "x".repeat(1024) ); - assert!(matches!(open(&ods(&text)), Err(Error::TooLarge(_)))); - // One row of cells each just under the 1 MiB cell limit, past 64 MiB in all: refused while + assert!(matches!(read(&ods(&text), &tight), Err(Error::TooLarge(_)))); + // One row of cells each just under the cell limit, past the text limit in all: refused while // the row is read. The row's end is never reached. - let long = format!(r#""#, "x".repeat(1024 * 1024 - 1)); - let cells = package(content(&format!(r#"{}"#, long.repeat(65))).as_bytes()).unwrap(); - assert!(matches!(open(&cells), Err(Error::TooLarge(_)))); + let long = format!(r#""#, "x".repeat(64 * 1024 - 1)); + let cells = package(content(&format!(r#"{}"#, long.repeat(17))).as_bytes()).unwrap(); + assert!(matches!(read(&cells, &tight), Err(Error::TooLarge(_)))); // A row repeated once more than its cells' text allows is refused, and one that fits reads. let cell = format!(r#""#, "y".repeat(1024)); let rows = |n: u32| { ods(&format!(r#"{cell}"#)) }; - assert!(open(&rows(65_536)).is_ok()); - assert!(matches!(open(&rows(65_537)), Err(Error::TooLarge(_)))); + assert!(read(&rows(1024), &tight).is_ok()); + assert!(matches!(read(&rows(1025), &tight), Err(Error::TooLarge(_)))); // An attribute over the cell text limit. let small = Options { max_cell_text: 10, ..Options::default() }; assert!(matches!( diff --git a/crates/openpgp/Cargo.toml b/crates/openpgp/Cargo.toml index 5630c3829..0bb9cbd16 100644 --- a/crates/openpgp/Cargo.toml +++ b/crates/openpgp/Cargo.toml @@ -24,6 +24,7 @@ sha3 = { version = "0.10", default-features = false } pgp = { version = "=0.21.0", default-features = false, features = ["wasm"] } [dev-dependencies] +craft-testkit = { workspace = true } proptest = { workspace = true } # Keys and signatures made in the tests, from a seed: the random numbers rPGP 0.21 takes. rand = { version = "0.8", default-features = false, features = ["std", "std_rng"] } diff --git a/crates/openpgp/src/keys_tests.rs b/crates/openpgp/src/keys_tests.rs index 3cc53b0bc..05db88fbe 100644 --- a/crates/openpgp/src/keys_tests.rs +++ b/crates/openpgp/src/keys_tests.rs @@ -253,6 +253,11 @@ fn a_copy_with_junk_subkey_bindings_from_the_future_never_pushes_out_the_real_on #[test] fn a_copy_that_costs_more_checks_than_a_key_may_is_refused_not_cut_short() { + // Forging and checking more signatures than the cap: nightly only. The revocation test below + // proves the same refusal with a smaller cap at the gate. + if craft_testkit::hostile::divisor() > 1 { + return; + } let alice = secret(ALICE, Make { subkey: true, ..Make::default() }); let mallory = secret("Mallory ", Make { seed: 6, ..Make::default() }); let mut copy = SignedPublicKey::from(alice.clone()); diff --git a/crates/proof/Cargo.toml b/crates/proof/Cargo.toml index 60cea674d..632016f4f 100644 --- a/crates/proof/Cargo.toml +++ b/crates/proof/Cargo.toml @@ -18,4 +18,5 @@ toml = { version = "1", default-features = false, features = ["parse", "serde", unicode-normalization = "0.1" [dev-dependencies] +craft-testkit = { workspace = true } proptest = { workspace = true } diff --git a/crates/proof/src/affix_suggest.rs b/crates/proof/src/affix_suggest.rs index ba72d8ebd..0ad2e5be1 100644 --- a/crates/proof/src/affix_suggest.rs +++ b/crates/proof/src/affix_suggest.rs @@ -883,7 +883,9 @@ mod tests { aff.push_str("SFX 9000 Y 1\nSFX 9000 0 s .\n"); let d = AffixDict::from_hunspell(&aff, "3\nb/1,5000\nab/2\nkot/9000\n", &[]).unwrap(); assert!(!d.stems().any(|s| s == "kots") && d.can_suggest("kots")); - for word in [input.clone(), input.to_uppercase()] { + // The gate asks for the word as typed; nightly adds the upper-case spelling (the case fallback). + let words = if craft_testkit::hostile::divisor() == 1 { vec![input.clone(), input.to_uppercase()] } else { vec![input.clone()] }; + for word in words { let got = suggest_in(&d, &word, 1, &Tuning::DEFAULT); assert_eq!(got.len(), 1, "accepted affixed candidate lost: {word}: {got:?}"); assert!(got[0].eq_ignore_ascii_case("kots"), "{word}: {got:?}"); diff --git a/crates/raw/Cargo.toml b/crates/raw/Cargo.toml index ddb1dbf2e..ffba4a6b6 100644 --- a/crates/raw/Cargo.toml +++ b/crates/raw/Cargo.toml @@ -70,6 +70,8 @@ zune-core = { version = "0.5", default-features = false, features = ["std"], opt jxl-oxide = { version = "0.12", default-features = false, optional = true } [dev-dependencies] +craft-testkit = { workspace = true } +craft-testkit = { workspace = true } proptest = { workspace = true } # The SHA-256 of the SR2 keystream known answer. sha2 = { version = "0.10", default-features = false, features = ["std"] } diff --git a/crates/raw/src/arw_lens.rs b/crates/raw/src/arw_lens.rs index b42d3afe0..c023bf071 100644 --- a/crates/raw/src/arw_lens.rs +++ b/crates/raw/src/arw_lens.rs @@ -1377,10 +1377,12 @@ mod tests { assert_eq!((h.lens_metadata, h.opcodes), (f.lens_metadata, f.opcodes)); } }; - for len in 0..good.len() { + // The gate runs every divisor-th truncation and byte; nightly runs every one. + let step = craft_testkit::hostile::divisor(); + for len in (0..good.len()).step_by(step) { check(&good[..len]); } - for at in (0..good.len()).filter(|at| !image.contains(at)) { + for at in (0..good.len()).step_by(step).filter(|at| !image.contains(at)) { for v in [0, 0xff, good[at] ^ 0x80, good[at] ^ 0x01] { let mut file = good.clone(); file[at] = v; diff --git a/crates/raw/tests/it/dng_lines.rs b/crates/raw/tests/it/dng_lines.rs index dd10c763c..a1acdb9dd 100644 --- a/crates/raw/tests/it/dng_lines.rs +++ b/crates/raw/tests/it/dng_lines.rs @@ -260,6 +260,10 @@ fn a_lossless_jpeg_larger_than_its_tile_is_refused_before_decoding_it_all() { #[test] fn short_lossy_jpeg_strips_are_charged_their_own_rows() { + // A 33-megapixel image next to the aggregate decode budget: nightly only. + if craft_testkit::hostile::divisor() > 1 { + return; + } // 8192 x 4096 RGB (below MAX_SAMPLES) in 16-row lossy JPEG strips: each strip's JPEG is exactly // 16 rows, so the decode budget charges 16 rows, not the 32 of the MCU padding allowance (which // would put the image over the aggregate budget and refuse it) diff --git a/crates/xml/Cargo.toml b/crates/xml/Cargo.toml index 02d68985b..d7743f973 100644 --- a/crates/xml/Cargo.toml +++ b/crates/xml/Cargo.toml @@ -14,3 +14,6 @@ workspace = true quick-xml = { version = "0.41", default-features = false } thiserror = { workspace = true } serde = { workspace = true, features = ["derive"] } + +[dev-dependencies] +craft-testkit = { workspace = true } diff --git a/crates/xml/tests/it/hostile.rs b/crates/xml/tests/it/hostile.rs index 19efdd235..1065a2dff 100644 --- a/crates/xml/tests/it/hostile.rs +++ b/crates/xml/tests/it/hostile.rs @@ -308,19 +308,24 @@ fn mismatched_tags_are_repaired_or_refused() { /// 5 MB of input. #[test] fn attributes_are_bounded_over_the_whole_tree() { - let el = format!("", " a=\"\"".repeat(1024)); - let doc = format!("{}", el.repeat(1025)); - let limits = Limits { max_attrs_total: 1024 * 1024, ..Limits::DEFAULT }; + // `ATTRS` attributes on each of `ATTRS + 1` elements, against a limit of `ATTRS` elements' worth. + const ATTRS: usize = 64; + let el = format!("", " a=\"\"".repeat(ATTRS)); + let doc = format!("{}", el.repeat(ATTRS + 1)); + let limits = Limits { max_attrs_total: ATTRS * ATTRS, ..Limits::DEFAULT }; let opts = Options::default().with_limits(limits); let err = opts.parse(doc.as_bytes()).unwrap_err(); - assert_eq!(err, Error::TooManyAttrsTotal(1024 * 1024)); + assert_eq!(err, Error::TooManyAttrsTotal(ATTRS * ATTRS)); assert!(err.is_limit()); // exactly at the limit is accepted - let fits = format!("{}", el.repeat(1024)); - assert_eq!(opts.parse(fits.as_bytes()).map(|r| r.children.len()), Ok(1024)); - // the default stops a document that is nothing but attributes - let hostile = format!("{}", el.repeat(4000)); - assert_eq!(parse(hostile.as_bytes()), Err(Error::TooManyAttrsTotal(4_000_000))); + let fits = format!("{}", el.repeat(ATTRS)); + assert_eq!(opts.parse(fits.as_bytes()).map(|r| r.children.len()), Ok(ATTRS)); + // the default stops a document that is nothing but attributes (millions of them: nightly only) + if craft_testkit::hostile::divisor() == 1 { + let el = format!("", " a=\"\"".repeat(1024)); + let hostile = format!("{}", el.repeat(4000)); + assert_eq!(parse(hostile.as_bytes()), Err(Error::TooManyAttrsTotal(4_000_000))); + } // streamed elements take their attributes with them: any number of rows, as long as the // ones held at once fit let mut rows = 0; @@ -328,9 +333,9 @@ fn attributes_are_bounded_over_the_whole_tree() { rows += c.attrs.len(); Ok::<(), Error>(()) }); - assert_eq!((rows, root.map(|r| r.children.len())), (1025 * 1024, Ok(0))); - let tight = Options::default().with_limits(Limits { max_attrs_total: 1023, ..Limits::DEFAULT }); - assert_eq!(tight.parse_streaming(doc.as_bytes(), &["c"], |_| Ok::<(), Error>(())), Err(Error::TooManyAttrsTotal(1023))); + assert_eq!((rows, root.map(|r| r.children.len())), ((ATTRS + 1) * ATTRS, Ok(0))); + let tight = Options::default().with_limits(Limits { max_attrs_total: ATTRS * ATTRS - 1, ..Limits::DEFAULT }); + assert_eq!(tight.parse_streaming(doc.as_bytes(), &["c"], |_| Ok::<(), Error>(())), Err(Error::TooManyAttrsTotal(ATTRS * ATTRS - 1))); } /// An internal subset is found wherever it hides, and looking for it is linear in the input.