craft-openpgp, craft-raw, craft-captions, craft-xml, craft-ods, craft-proof, craft-font-subset, craft-drawingml: smaller or gated passes

This commit is contained in:
aiongg
2026-11-24 19:48:21 +00:00
parent 459aae1e80
commit 0593def5d0
15 changed files with 58 additions and 26 deletions
+1
View File
@@ -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"
+2 -1
View File
@@ -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) {
+1 -1
View File
@@ -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);
+1
View File
@@ -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"
+3 -1
View File
@@ -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] {
+10 -8
View File
@@ -206,23 +206,25 @@ fn expansion_bounds_stop_small_repeat_bombs() {
r#"<table:table table:name="Data"><table:table-row table:number-rows-repeated="1048576"><table:table-cell office:value-type="float" office:value="1"/></table:table-row></table:table>"#,
);
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#"<table:table table:name="Data"><table:table-row table:number-rows-repeated="100000"><table:table-cell office:value-type="string" office:string-value="{}"/></table:table-row></table:table>"#,
r#"<table:table table:name="Data"><table:table-row table:number-rows-repeated="2000"><table:table-cell office:value-type="string" office:string-value="{}"/></table:table-row></table:table>"#,
"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#"<table:table-cell office:value-type="string" office:string-value="{}"/>"#, "x".repeat(1024 * 1024 - 1));
let cells = package(content(&format!(r#"<table:table table:name="Data"><table:table-row>{}"#, long.repeat(65))).as_bytes()).unwrap();
assert!(matches!(open(&cells), Err(Error::TooLarge(_))));
let long = format!(r#"<table:table-cell office:value-type="string" office:string-value="{}"/>"#, "x".repeat(64 * 1024 - 1));
let cells = package(content(&format!(r#"<table:table table:name="Data"><table:table-row>{}"#, 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#"<table:table-cell office:value-type="string" office:string-value="{}"/>"#, "y".repeat(1024));
let rows = |n: u32| {
ods(&format!(r#"<table:table table:name="Data"><table:table-row table:number-rows-repeated="{n}">{cell}</table:table-row></table:table>"#))
};
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!(
+1
View File
@@ -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"] }
+5
View File
@@ -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 <mallory@example.org>", Make { seed: 6, ..Make::default() });
let mut copy = SignedPublicKey::from(alice.clone());
+1
View File
@@ -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 }
+3 -1
View File
@@ -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:?}");
+2
View File
@@ -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"] }
+4 -2
View File
@@ -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;
+4
View File
@@ -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)
+3
View File
@@ -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 }
+17 -12
View File
@@ -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!("<c{}/>", " a=\"\"".repeat(1024));
let doc = format!("<r>{}</r>", 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!("<c{}/>", " a=\"\"".repeat(ATTRS));
let doc = format!("<r>{}</r>", 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!("<r>{}</r>", 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!("<r>{}</r>", el.repeat(4000));
assert_eq!(parse(hostile.as_bytes()), Err(Error::TooManyAttrsTotal(4_000_000)));
let fits = format!("<r>{}</r>", 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!("<c{}/>", " a=\"\"".repeat(1024));
let hostile = format!("<r>{}</r>", 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.