From af92d450cea7016d26e65ddd9a0f6ef8b3df99fc Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 14 Nov 2026 14:20:09 -0500 Subject: [PATCH] PDF import: cap the input at 1 GiB The import path set the reader's max_input_bytes to usize::MAX, so it accepted a PDF of any size and copied it whole before parsing. A real ceiling of 1 GiB keeps ordinary documents while refusing a file that would exhaust memory; stream decoding keeps its own per-document limits. --- crates/pdf/src/pages.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/pdf/src/pages.rs b/crates/pdf/src/pages.rs index 013d09f22d..9c4b66b3c6 100644 --- a/crates/pdf/src/pages.rs +++ b/crates/pdf/src/pages.rs @@ -312,10 +312,15 @@ pub struct TrimPages { pub bleed: [f64; 4], } -/// Preserve the application's existing accepted file sizes. Ordinary stream decoding still -/// uses the shared reader's immutable per-document limits, and its input copy is fallible. +/// Most bytes a PDF may be before it is refused. An import reads the file whole, so this bounds +/// the copy instead of letting a crafted file name any size (audit: VectorCraft #4). +const MAX_PDF_INPUT_BYTES: usize = 1 << 30; + +/// Preserve the application's existing accepted file sizes, up to a real ceiling. Ordinary stream +/// decoding still uses the shared reader's immutable per-document limits, and its input copy is +/// fallible. pub(crate) fn open_options() -> craft_pdf::OpenOptions { - craft_pdf::OpenOptions { max_input_bytes: usize::MAX, ..Default::default() } + craft_pdf::OpenOptions { max_input_bytes: MAX_PDF_INPUT_BYTES, ..Default::default() } } pub(crate) fn open_with_options(bytes: &[u8], password: Option<&str>, options: &craft_pdf::OpenOptions) -> Result {