mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-25 02:29:31 -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>
36 lines
1.3 KiB
Rust
36 lines
1.3 KiB
Rust
#[cfg(feature = "font_embedding")]
|
|
#[test]
|
|
fn test_font_data_creation() {
|
|
// Load a sample TTF font file from the test resources
|
|
let font_file = std::fs::read("./assets/fonts/Montserrat-Regular.ttf");
|
|
|
|
// Ensure the font file was read successfully
|
|
assert!(font_file.is_ok(), "Failed to read font file");
|
|
|
|
// Unwrap the result to get the font file bytes
|
|
let font_file = font_file.unwrap();
|
|
let mut font_data = lopdf::FontData::new(&font_file, "Montserrat-Regular".to_string());
|
|
|
|
// Create a new FontData instance
|
|
font_data
|
|
.set_font_bbox((0, -200, 1000, 800))
|
|
.set_italic_angle(10)
|
|
.set_ascent(800)
|
|
.set_descent(-200)
|
|
.set_cap_height(700)
|
|
.set_stem_v(100)
|
|
.set_flags(4)
|
|
.set_encoding("WinAnsiEncoding".to_string());
|
|
|
|
// Verify the properties of the FontData instance
|
|
assert_eq!(font_data.font_bbox, (0, -200, 1000, 800));
|
|
assert_eq!(font_data.italic_angle, 10);
|
|
assert_eq!(font_data.ascent, 800);
|
|
assert_eq!(font_data.descent, -200);
|
|
assert_eq!(font_data.cap_height, 700);
|
|
assert_eq!(font_data.stem_v, 100);
|
|
assert_eq!(font_data.flags, 4);
|
|
assert_eq!(font_data.encoding, "WinAnsiEncoding");
|
|
assert!(!font_data.bytes().is_empty(), "Font data should not be empty");
|
|
}
|