pdftract/tests/test_bomb_limit.rs
jedarden 432514d350 wip: AcroForm improvements, debug tooling, test corpus, and fixture updates
Collects in-progress work across forms (Ch/Tx field handling, value_text
edge cases), layout corrections, stream parser fixes, conformance test
expansion, security audit test (TH-08), stream-decoder bomb fixture,
debug examples reorganization under examples/debug/, sdk module scaffold,
xtask CLI enhancements, and provenance entries for new fixtures.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 09:48:14 -04:00

33 lines
1.2 KiB
Rust

//! Quick test to verify bomb limit works correctly
use std::time::Instant;
#[test]
fn test_bomb_limit_simple() {
let bomb_data = std::fs::read("tests/stream_decoder/fixtures/flate_bomb_3gb.bin")
.expect("Failed to read bomb fixture");
println!("Bomb fixture size: {} bytes", bomb_data.len());
let start = Instant::now();
let mut counter = 0;
let bomb_limit = 1_000_000_000; // 1 GB
use pdftract_core::parser::stream::FlateDecoder;
let result = FlateDecoder.decode(&bomb_data, None, &mut counter, bomb_limit);
let elapsed = start.elapsed();
println!("Decode completed in {:?}", elapsed);
assert!(result.is_ok());
let output = result.unwrap();
println!("Output size: {} bytes", output.len());
// Should complete in < 5 seconds
assert!(elapsed.as_secs() < 5, "Bomb test took too long: {:?}", elapsed);
// Output should be truncated near the limit
assert!(output.len() as u64 <= bomb_limit + 1_000_000,
"Output {} exceeds bomb limit {} by too much", output.len(), bomb_limit);
assert!(output.len() as u64 >= 900_000_000,
"Output {} is much smaller than expected", output.len());
}