mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-17 08:05:21 +00:00
Fuzz targets for PDF/A verify and convert (#6308)
Co-authored-by: eliets2 <287273517+eliets2@users.noreply.github.com>
This commit is contained in:
1 parent
c15c909745
commit
9a95273c7c
3 files changed
+75
No files matched your search
@@ -0,0 +1,32 @@
|
||||
[package]
|
||||
name = "pdfcraft-preflight-fuzz"
|
||||
version = "0.0.0"
|
||||
publish = false
|
||||
edition = "2024"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[package.metadata]
|
||||
cargo-fuzz = true
|
||||
|
||||
# Detached from the PdfCraft workspace: run with `cargo +nightly fuzz run verify`
|
||||
# from crates/preflight/.
|
||||
[workspace]
|
||||
|
||||
[dependencies]
|
||||
libfuzzer-sys = "0.4"
|
||||
pdfcraft-cos = { path = "../../cos" }
|
||||
pdfcraft-preflight = { path = ".." }
|
||||
|
||||
[[bin]]
|
||||
name = "verify"
|
||||
path = "fuzz_targets/verify.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
|
||||
[[bin]]
|
||||
name = "convert"
|
||||
path = "fuzz_targets/convert.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
@@ -0,0 +1,21 @@
|
||||
//! Feeds arbitrary bytes to `convert` at level A2b; the report it returns is discarded.
|
||||
#![no_main]
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use pdfcraft_cos::Document;
|
||||
use pdfcraft_preflight::{Level, convert};
|
||||
|
||||
/// Largest input the target parses; a longer input is dropped before `Document::open` copies it.
|
||||
const MAX_INPUT: usize = 16 << 20;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
if data.len() > MAX_INPUT {
|
||||
return;
|
||||
}
|
||||
let Ok(mut doc) = Document::open(Arc::new(data.to_vec())) else {
|
||||
return;
|
||||
};
|
||||
let _ = convert(&mut doc, Level::A2b);
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
//! Feeds arbitrary bytes to `verify` at both levels; the issue list it returns is discarded.
|
||||
#![no_main]
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use pdfcraft_cos::Document;
|
||||
use pdfcraft_preflight::{Level, verify};
|
||||
|
||||
/// Largest input the target parses; a longer input is dropped before `Document::open` copies it.
|
||||
const MAX_INPUT: usize = 16 << 20;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
if data.len() > MAX_INPUT {
|
||||
return;
|
||||
}
|
||||
let Ok(doc) = Document::open(Arc::new(data.to_vec())) else {
|
||||
return;
|
||||
};
|
||||
let _a2b = verify(&doc, Level::A2b);
|
||||
let _a3b = verify(&doc, Level::A3b);
|
||||
});
|
||||
Reference in new issue
Block a user