Fuzzing: catch the app's own caught panics as the app does
libFuzzer's panic hook aborts at once, even inside the app's own catch_unwind (pack::pdf::copies around the PDF reader), so the third run stopped on the replayed PDF case after 8 inputs although the app handles it. The targets' init (fuzzing::init) sets a hook that prints the first ten panics and lets them unwind as in the app; a panic nothing catches still reaches libfuzzer-sys's own catch_unwind, which aborts and saves the input. Checked in a container: the PDF case passes in 8 ms, 60 s a target finds nothing. PLAN lists the two findings.
This commit is contained in:
1 parent
c0ef994b26
commit
422ee2ec2c
5 files changed
+44
-6
No files matched your search
+13
-3
@@ -748,9 +748,19 @@ cases in the tests.
|
||||
`tests/fuzz_cases/<target>/` with its fix, which `cargo test` replays on
|
||||
every push. The multipart reading itself is axum's (multer), so no
|
||||
target of ours.
|
||||
- [ ] The nightly job runs on runner02 on cnx01 (Alex, Nov 23, 2026), by
|
||||
its own label `cnx01` (cnx-network-clan PR), at 03:00 and at the lowest
|
||||
CPU priority (`nice`), so the app keeps first call on the CPU.
|
||||
- [x] The nightly job runs on runner02 on cnx01 (Alex, Nov 23, 2026), by
|
||||
its own label `cnx01` (cnx-network-clan PR #170), at 03:00 and at the
|
||||
lowest CPU priority (`nice`), so the app keeps first call on the CPU.
|
||||
Its first two runs found two bugs, both fixed and replayed from
|
||||
`tests/fuzz_cases/`:
|
||||
- a drawn signature of 798 bytes whose PNG header claimed 300 x
|
||||
738,197,594 pixels made the app ask for 885 GB, and the failed
|
||||
allocation ended the whole app. Pictures are now sized from their
|
||||
header before krilla decodes them (`papers::picture`, at most 50
|
||||
megapixels);
|
||||
- a broken PDF upload made the PDF reader panic, so that person's pack
|
||||
failed every time. Such a file now prints as a note page
|
||||
(`pack::pdf::copies`).
|
||||
|
||||
## Open questions
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#![no_main]
|
||||
|
||||
libfuzzer_sys::fuzz_target!(|data: &[u8]| visa::fuzzing::signed_copy(data));
|
||||
libfuzzer_sys::fuzz_target!(
|
||||
init: visa::fuzzing::init(),
|
||||
|data: &[u8]| visa::fuzzing::signed_copy(data)
|
||||
);
|
||||
@@ -1,3 +1,6 @@
|
||||
#![no_main]
|
||||
|
||||
libfuzzer_sys::fuzz_target!(|data: &[u8]| visa::fuzzing::text(data));
|
||||
libfuzzer_sys::fuzz_target!(
|
||||
init: visa::fuzzing::init(),
|
||||
|data: &[u8]| visa::fuzzing::text(data)
|
||||
);
|
||||
@@ -1,3 +1,6 @@
|
||||
#![no_main]
|
||||
|
||||
libfuzzer_sys::fuzz_target!(|data: &[u8]| visa::fuzzing::upload(data));
|
||||
libfuzzer_sys::fuzz_target!(
|
||||
init: visa::fuzzing::init(),
|
||||
|data: &[u8]| visa::fuzzing::upload(data)
|
||||
);
|
||||
@@ -9,6 +9,25 @@ use chrono::NaiveDate;
|
||||
|
||||
use crate::{agreements, conflicts, dates, files, gps, legal, mrz, pack, records};
|
||||
|
||||
/// Run once before a fuzz target's first input. libFuzzer's panic hook
|
||||
/// aborts at once, even inside the app's own `catch_unwind` (around the PDF
|
||||
/// reader, `pack::pdf::copies`), which is not how the app runs. This hook
|
||||
/// prints the panic (the first ten; a caught one can recur on every input)
|
||||
/// and lets it unwind as in the app. A panic nothing catches still reaches
|
||||
/// libfuzzer-sys, which counts it as a finding and saves its input; the
|
||||
/// replay test (`tests/fuzz_cases.rs`) then shows its message.
|
||||
pub fn init() {
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
static SEEN: AtomicUsize = AtomicUsize::new(0);
|
||||
std::panic::set_hook(Box::new(|info| {
|
||||
match SEEN.fetch_add(1, Ordering::Relaxed) {
|
||||
0..10 => eprintln!("{info}"),
|
||||
10 => eprintln!("(further panics not shown)"),
|
||||
_ => {}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/// A target's body: bytes in, a panic when something is wrong.
|
||||
pub type Target = fn(&[u8]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user