craft-docx, craft-drawingml: smaller sizes and nightly-only boundary tests

This commit is contained in:
aiongg
2026-11-24 19:45:55 +00:00
parent ad88ed14ed
commit 7c31a1ea9f
8 changed files with 34 additions and 20 deletions
+1
View File
@@ -28,6 +28,7 @@ zeroize = "1"
[dev-dependencies]
craft-cfb = { workspace = true }
craft-testkit = { workspace = true }
craft-opc = { workspace = true, features = ["test-support"] }
craft-wordmodel = { workspace = true, features = ["test-support"] }
image = { version = "0.25", default-features = false, features = ["png"] }
+5 -4
View File
@@ -230,11 +230,12 @@ fn hostile_radar_charts_never_panic() {
let small =
chart_items(&space(&format!("<c:radarChart>{}</c:radarChart>", ser(0, "S", None, &["a", "b", "c"], &["1", "2", "3"]))), &theme(), 20.0, 20.0);
let _ = small;
// Caps: thousands of categories and series stay bounded.
let cats: Vec<String> = (0..5000).map(|i| format!("c{i}")).collect();
// Caps: three times as many categories and series as are drawn stay bounded.
let n = 3 * MAX_SPOKES;
let cats: Vec<String> = (0..n).map(|i| format!("c{i}")).collect();
let refs: Vec<&str> = cats.iter().map(String::as_str).collect();
let vals = vec!["1"; 5000];
let many: Vec<String> = (0..300).map(|i| ser(i, "S", None, &refs, &vals)).collect();
let vals = vec!["1"; n];
let many: Vec<String> = (0..3 * MAX_RADAR_SERIES).map(|i| ser(i, "S", None, &refs, &vals)).collect();
let items = radar_chart("marker", &many);
let polygons = items.iter().filter(|it| matches!(it, GraphicItem::Path { stroke: Some(c), .. } if *c != GRID)).count();
assert!(polygons <= MAX_RADAR_SERIES, "{polygons}");
+3 -3
View File
@@ -29,8 +29,8 @@ fn cpu_cost(mut f: impl FnMut()) -> f64 {
#[test]
fn many_comments_save_without_quadratic_id_searches() {
for imported in [true, false] {
let small = comments(4_000, imported);
let big = comments(32_000, imported);
let small = comments(1_000, imported);
let big = comments(8_000, imported);
let save = |d: &Document| drop(std::hint::black_box(craft_docx::write(d).unwrap()));
save(&small);
save(&big);
@@ -39,7 +39,7 @@ fn many_comments_save_without_quadratic_id_searches() {
// use elapsed time; retry ratios far from linear before declaring a regression.
for _ in 0..3 {
let (mut s, mut b) = (f64::INFINITY, f64::INFINITY);
for _ in 0..3 {
for _ in 0..2 {
s = s.min(cpu_cost(|| (0..8).for_each(|_| save(&small))) / 8.0);
b = b.min(cpu_cost(|| save(&big)));
}
@@ -59,7 +59,7 @@ fn cost_ratio(scale: usize, mut small: impl FnMut(), mut big: impl FnMut()) -> (
big();
let mut small_scaled = || (0..scale).for_each(|_| small());
let (mut t1, mut tk) = (f64::INFINITY, f64::INFINITY);
for _ in 0..5 {
for _ in 0..3 {
let a = Instant::now();
small_scaled();
t1 = t1.min(a.elapsed().as_secs_f64() / scale as f64);
@@ -76,8 +76,8 @@ fn cost_ratio(scale: usize, mut small: impl FnMut(), mut big: impl FnMut()) -> (
#[test]
fn a_document_with_many_inline_content_controls_saves_in_linear_time() {
let scale = 4;
let small = inline_controls(8_000);
let big = inline_controls(8_000 * scale);
let small = inline_controls(2_000);
let big = inline_controls(2_000 * scale);
let (t1, tk, ratio) = cost_ratio(
scale,
|| {
@@ -96,8 +96,8 @@ fn a_document_with_many_inline_content_controls_saves_in_linear_time() {
#[test]
fn a_document_with_many_block_content_controls_saves_in_linear_time() {
let scale = 4;
let small = block_controls(8_000);
let big = block_controls(8_000 * scale);
let small = block_controls(2_000);
let big = block_controls(2_000 * scale);
let (t1, tk, ratio) = cost_ratio(
scale,
|| {
+5
View File
@@ -9,6 +9,11 @@ const W_NS: &str = r#"xmlns:w="http://schemas.openxmlformats.org/wordprocessingm
#[test]
fn a_file_of_element_budget_parts_still_reads() {
// 18M elements: nightly only. `the_xml_element_budget_is_package_wide` (in `package.rs`) proves
// the package-wide budget with a small one at the gate.
if craft_testkit::hostile::divisor() > 1 {
return;
}
// Nine chart parts of 2M elements each: 18M over the package's 16M budget. The later
// parts are skipped with a warning instead of built, and the file still reads. Before
// the budget, every part's whole tree was parsed and the chart trees stayed cached for
+4 -2
View File
@@ -313,11 +313,13 @@ fn compound(info: &[u8], package: &[u8]) -> Vec<u8> {
proptest! {
// Each case that parses runs the 50,000-spin key derivation, so fewer cases.
#![proptest_config(ProptestConfig { cases: 48, ..ProptestConfig::default() })]
#![proptest_config(ProptestConfig { cases: (48 / craft_testkit::hostile::divisor() as u32).max(6), ..ProptestConfig::default() })]
#[test]
fn mutated_standard_encryption_never_panics(ops in proptest::collection::vec((0u8..3, any::<prop::sample::Index>(), any::<u8>(), any::<bool>()), 1..8)) {
let (mut info, mut package) = standard_streams();
// Encrypting runs the key derivation too: once for every case.
static STREAMS: std::sync::OnceLock<(Vec<u8>, Vec<u8>)> = std::sync::OnceLock::new();
let (mut info, mut package) = STREAMS.get_or_init(standard_streams).clone();
for (k, idx, byte, in_package) in ops {
let x = if in_package { &mut package } else { &mut info };
let at = idx.index(x.len() + 1);
+4
View File
@@ -268,6 +268,10 @@ fn flat_opc_limits_count_what_is_not_kept() {
assert!(limited(&r#"<pkg:part pkg:name="/word/media/dot.png"><pkg:binaryData>AA==</pkg:binaryData></pkg:part>"#.repeat(20_000)));
assert!(limited(&"<x/>".repeat(20_000)));
// A part nothing reads, one element over what the XML tree reader takes in a part (8 000 000).
// Millions of elements: nightly only; the checks above prove the same counting at the gate.
if craft_testkit::hostile::divisor() > 1 {
return;
}
assert!(limited(&format!(r#"<pkg:part pkg:name="/word/unused.xml"><pkg:xmlData><r>{}</r></pkg:xmlData></pkg:part>"#, "<y/>".repeat(8_000_000))));
}
+7 -6
View File
@@ -1762,8 +1762,8 @@ mod chartex_tests {
#[test]
fn large_box_hierarchy_and_stacked_charts_take_linear_work() {
// 50,000 distinct categories in one series: grouped through a map, one pass.
let n = 50_000;
// 5,000 distinct categories in one series: grouped through a map, one pass.
let n = 5_000;
let mut c = Chart::sample(ChartType::BoxWhisker);
c.series.truncate(1);
c.categories = (0..n).map(|i| format!("g{i}")).collect();
@@ -1771,12 +1771,13 @@ mod chartex_tests {
let (groups, stats) = c.box_groups();
assert_eq!((groups.len(), stats[0].len()), (n, n));
assert!(stats[0].iter().all(Option::is_some));
// 2,000 series cap the groups so the result stays within MAX_BOX_CELLS.
c.series = vec![c.series[0].clone(); 2000];
// Enough series to cap the groups so the result stays within MAX_BOX_CELLS.
let series = MAX_BOX_CELLS / n * 2;
c.series = vec![c.series[0].clone(); series];
let (groups, stats) = c.box_groups();
assert_eq!(groups.len(), MAX_BOX_CELLS / 2000);
assert_eq!(groups.len(), MAX_BOX_CELLS / series);
assert!(stats.iter().all(|s| s.len() == groups.len()));
// One long outer label over 50,000 leaves is shared, not copied per leaf.
// One long outer label over 5,000 leaves is shared, not copied per leaf.
let mut t = Chart::sample(ChartType::Treemap);
t.series.truncate(1);
t.categories = (0..n).map(|i| format!("c{i}")).collect();