From b40ea27592a9f6408694d3fdb35e753373b0a7e2 Mon Sep 17 00:00:00 2001 From: centy Date: Sun, 22 Nov 2026 09:04:25 -0500 Subject: [PATCH] Put a left-out image's filters back before skipping its data; test the measuring charge materialize now empties a file whose decode failed, so the reduced image that is left out restores its pending filters for skip_data. The new test runs an image over 300 MB of compressed zeros from a reusable stream in a loop until the operation budget ends. Co-Authored-By: Claude Fable 5.2 --- crates/eps/src/import/data/ops.rs | 13 ++++++++++++- crates/eps/src/import/tests_images.rs | 16 ++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/crates/eps/src/import/data/ops.rs b/crates/eps/src/import/data/ops.rs index ce1c811d43..b59d0102ab 100644 --- a/crates/eps/src/import/data/ops.rs +++ b/crates/eps/src/import/data/ops.rs @@ -936,11 +936,22 @@ impl Interp<'_> { }; for src in s.sources.iter().filter(|_| streamed.is_none()) { if let Source::File(f) = src { + // A decode that fails leaves the file empty (`materialize`), but a reduced image + // that is left out still has its data to skip: its filters are put back for that. + let pending = match &*f.borrow() { + Stream::Pending { chain, from } => Some((chain.clone(), from.clone())), + _ => None, + }; match self.materialize(f) { Ok(()) => {} // Decoded data past the cap: a reduced image is left out (its data skipped) // rather than failing the file, as an image too large to read at all is. - Err(PsError::Limit(_)) if step > 1 => return Ok(self.leave_out(&s)), + Err(PsError::Limit(_)) if step > 1 => { + if let Some((chain, from)) = pending { + *f.borrow_mut() = Stream::Pending { chain, from }; + } + return Ok(self.leave_out(&s)); + } Err(e) => return Err(e), } } diff --git a/crates/eps/src/import/tests_images.rs b/crates/eps/src/import/tests_images.rs index 26b3499495..a9385f8eff 100644 --- a/crates/eps/src/import/tests_images.rs +++ b/crates/eps/src/import/tests_images.rs @@ -668,16 +668,16 @@ fn the_data_of_an_image_too_large_to_hold_is_skipped() { } /// Measuring the data of an image too large to hold decompresses it, and that is charged to the -/// operation budget: a small compressed stream that decodes to 300 MB, kept in a reusable stream -/// and measured again on every pass of a loop, runs out of the budget. +/// operation budget: a program kept in a reusable stream, whose image over 300 MB of compressed +/// zeros is left out and measured again each time a loop runs the stream from its start, runs out +/// of the budget. #[test] fn measuring_data_too_large_to_hold_in_a_loop_runs_out_of_the_budget() { - let data = crate::ps::ascii85(&crate::ps::deflate(&vec![0u8; 300 << 20])); - super::tests::runs_out_of_budget(&format!( - "/R currentfile /ASCII85Decode filter /ReusableStreamDecode filter def -{data} - {{ R 0 setfileposition 10000 10000 8 [1 0 0 1 0 0] R << /Predictor 15 /Colors 3 /Columns 10000 >> /FlateDecode filter false 3 colorimage }} loop" - )); + let mut program = + b"10000 10000 8 [1 0 0 1 0 0] currentfile << /Predictor 15 /Colors 3 /Columns 10000 >> /FlateDecode filter false 3 colorimage\n".to_vec(); + program.extend(crate::ps::deflate(&vec![0u8; 300 << 20])); + let hex: String = program.iter().map(|b| format!("{b:02x}")).collect(); + super::tests::runs_out_of_budget(&format!("/P <{hex}> /ReusableStreamDecode filter def {{ P 0 setfileposition P cvx exec }} loop")); } /// When an image too large to read is left out, the data of its mask (`InterleaveType` 3) is