mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 20:01:07 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
2de6e34c52
commit
b40ea27592
2 files changed
+20
-9
No files matched your search
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user