Pack: a PDF whose pages cannot be copied gets a note page
CI / secret scan (push) Successful in 9s
CI / fmt, clippy, tests (push) Successful in 55s
CI / release (push) Skipped

The second fuzz run on cnx01 found a PDF (a page's font dictionary with
a key and a broken value) on which the PDF reader, hayro-syntax 0.7.2
(Dict::entries, an unwrap), panics while the page is copied. The app
lives on (the pack renders in spawn_blocking), but the person's pack
and the card's sides failed with a 500 every time, for as long as the
file was among their documents. piece() now copies an uploaded PDF's
pages once into a throwaway document with panics caught
(pack::pdf::copies); a file that panics prints as a note page like any
unreadable file. Only a panic counts, so a PDF 2.0 file still goes to
render's retry.

tests/fuzz_cases/upload/pdf-dict-key-without-value.pdf is the finding,
replayed on every push (it panicked on stable too).
This commit is contained in:
grabowski committed 2026-11-23 10:35:33 +07:00
1 parent b7c9818dd6
commit c0ef994b26
3 files changed
+29 -1

No files matched your search

+23 -1
View File
@@ -118,10 +118,15 @@ fn piece(what: &str, file: Option<Loaded>) -> Piece {
Ok(pdf) => {
let sizes: Vec<(f32, f32)> =
pdf.pages().iter().map(|p| p.render_dimensions()).collect();
let doc = PdfDocument::new(Arc::new(pdf));
if sizes.is_empty() {
Piece::Note(format!("{what}: {name} has no pages."))
} else if !copies(&doc, &sizes) {
Piece::Note(format!(
"{what}: {name} is a PDF the app cannot copy pages from. {later}"
))
} else {
Piece::Pdf(PdfDocument::new(Arc::new(pdf)), sizes)
Piece::Pdf(doc, sizes)
}
}
Err(e) => Piece::Note(format!(
@@ -137,6 +142,23 @@ fn piece(what: &str, file: Option<Loaded>) -> Piece {
}
}
/// Whether the pages of an uploaded PDF can be copied: tried once into a
/// throwaway document. The PDF reader panics on some broken files (the
/// nightly fuzzing found a font dictionary with a key and no value), which
/// would fail the whole pack, every time, for as long as the file is there;
/// such a file gets a note page instead. Only a panic counts: an error from
/// `finish` (a PDF 2.0 file in a 1.7 document) is for `render` to handle.
fn copies(pdf: &PdfDocument, sizes: &[(f32, f32)]) -> bool {
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
let mut doc = Document::new();
for (k, &(w, h)) in sizes.iter().enumerate() {
pdf_page(&mut doc, pdf, k, w, h);
}
let _ = doc.finish();
}))
.is_ok()
}
/// An image to print: the picture, how to turn it upright, its pixels'
/// size on paper and the box its kind prints in.
struct Shot {