mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-26 11:08:48 -06:00
Fuzzed inputs drove one check-one process to 2-6 GB (the 16 GB CI runner running two of them was killed every night). Three causes, each with a test: - lopdf (bootstrap inspector) sized PNG predictor rows from /Columns before reading data: /Columns 4294967295 allocated two 4 GiB rows. Vendored lopdf 0.45.0 refuses rows longer than the data (and uses saturating row widths); its load-time stream decoding also gets a 256 MiB limit (it had none). - hayro sized a tiling pattern's cell pixmap from /XStep x scale, bounded only by u16: a step far beyond /BBox allocated 2 GB. The vendored patch keeps the cell within 3000 px a side, lowering the resolution instead. - cos decoded cross-reference streams up to the general 1 GiB limit; they now stop at what 8,388,607 objects' rows can hold (~200 MB at most), and the section is reconstructed (logged) instead. On the nightly's seed (41) the worst captured input fell from 6.2 GB to 6 MB, and a 300 s fuzz run had no process above 300 MB (before: many at 2-5 GB). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
41 lines
1.3 KiB
Rust
41 lines
1.3 KiB
Rust
#[cfg(not(feature = "async"))]
|
|
use lopdf::Document;
|
|
#[cfg(not(feature = "async"))]
|
|
use std::time::Instant;
|
|
|
|
#[cfg(not(feature = "async"))]
|
|
#[test]
|
|
fn page_count_meta_data_performance_test() {
|
|
let document_path = "assets/test.pdf";
|
|
let start_time = Instant::now();
|
|
let doc = Document::load_metadata(document_path).expect("Failed to load document");
|
|
let result = doc.page_count;
|
|
let elapsed_time = start_time.elapsed();
|
|
println!("--- Meta Page Count Stats ---");
|
|
println!("Page count: {} in {:.2}s", result, elapsed_time.as_secs_f64());
|
|
assert_eq!(result, 100);
|
|
assert!(
|
|
elapsed_time.as_millis() < 100,
|
|
"Expected load in <100ms, got {}ms",
|
|
elapsed_time.as_millis()
|
|
);
|
|
}
|
|
|
|
#[cfg(not(feature = "async"))]
|
|
#[test]
|
|
fn page_count_performance_test() {
|
|
let document_path = "assets/test.pdf";
|
|
let start_time = Instant::now();
|
|
let doc = Document::load(document_path).expect("Failed to load document");
|
|
let result = doc.get_pages().len();
|
|
let elapsed_time = start_time.elapsed();
|
|
println!("--- Page Count Stats ---");
|
|
println!("Page count: {} in {:.2}s", result, elapsed_time.as_secs_f64());
|
|
assert_eq!(result, 100);
|
|
assert!(
|
|
elapsed_time.as_millis() < 100,
|
|
"Expected load in <100ms, got {}ms",
|
|
elapsed_time.as_millis()
|
|
);
|
|
}
|