From 88fc414dc3bb7ba8c47cbc6ae157d3908fb751ff Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 11 Nov 2026 00:00:23 +0000 Subject: [PATCH] address review: cap page content read at the 256 MiB decode limit --- crates/plate-test/src/structure.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/plate-test/src/structure.rs b/crates/plate-test/src/structure.rs index bae1dca5b..ecba7287d 100644 --- a/crates/plate-test/src/structure.rs +++ b/crates/plate-test/src/structure.rs @@ -69,6 +69,9 @@ pub struct ExtGState { pub smask_tr: bool, } +/// The most decoded content bytes read per page (the former `page.operations()` decode limit). +const MAX_PAGE_CONTENT: usize = 256 * 1024 * 1024; + /// Summarize `pdf`. Malformed objects are skipped rather than reported. pub fn summarize(pdf: &[u8]) -> Result { let pdf = Pdf::new(Arc::new(pdf.to_vec())).map_err(|e| Error::Read(format!("{e:?}")))?; @@ -88,7 +91,7 @@ pub fn summarize(pdf: &[u8]) -> Result { // Read and dropped page by page: `page.operations()` keeps every page's decoded content // for as long as the document, so pages sharing one stream would each hold a copy. let mut content = Vec::new(); - page.content_reader().read_into(&mut content, usize::MAX); + page.content_reader().read_into(&mut content, MAX_PAGE_CONTENT); walk.operators(&mut UntypedIter::new(&content)); let res = page.resources(); walk.resources(&Resources {