Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0ef994b26 |
No files matched your search
+23
-1
@@ -118,10 +118,15 @@ fn piece(what: &str, file: Option<Loaded>) -> Piece {
|
|||||||
Ok(pdf) => {
|
Ok(pdf) => {
|
||||||
let sizes: Vec<(f32, f32)> =
|
let sizes: Vec<(f32, f32)> =
|
||||||
pdf.pages().iter().map(|p| p.render_dimensions()).collect();
|
pdf.pages().iter().map(|p| p.render_dimensions()).collect();
|
||||||
|
let doc = PdfDocument::new(Arc::new(pdf));
|
||||||
if sizes.is_empty() {
|
if sizes.is_empty() {
|
||||||
Piece::Note(format!("{what}: {name} has no pages."))
|
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 {
|
} else {
|
||||||
Piece::Pdf(PdfDocument::new(Arc::new(pdf)), sizes)
|
Piece::Pdf(doc, sizes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => Piece::Note(format!(
|
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'
|
/// An image to print: the picture, how to turn it upright, its pixels'
|
||||||
/// size on paper and the box its kind prints in.
|
/// size on paper and the box its kind prints in.
|
||||||
struct Shot {
|
struct Shot {
|
||||||
|
|||||||
@@ -1,2 +1,8 @@
|
|||||||
Inputs that once broke the fuzz target `upload` (src/fuzzing.rs), replayed by
|
Inputs that once broke the fuzz target `upload` (src/fuzzing.rs), replayed by
|
||||||
`tests/fuzz_cases.rs`. Name each after what it broke.
|
`tests/fuzz_cases.rs`. Name each after what it broke.
|
||||||
|
|
||||||
|
- `pdf-dict-key-without-value.pdf`: a page whose font dictionary has a key
|
||||||
|
and a broken value (found Nov 23, 2026). The PDF reader (hayro-syntax 0.7.2,
|
||||||
|
`Dict::entries`) panicked while the page was copied, so the pack failed
|
||||||
|
with a 500 every time; `pack::pdf::copies` now tries the pages once and
|
||||||
|
the file gets a note page.
|
||||||
Binary file not shown.
Reference in new issue
Block a user