Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Merge origin/main into feat/jbig2-run-allowance

FredAppsbc4acf7bfc74
diff --cc crates/cos/src/document/objects.rs
index 9d47fd9bd,bab99ac45..ec7078590
--- a/crates/cos/src/document/objects.rs
+++ b/crates/cos/src/document/objects.rs
@@@ -333,10 -322,21 +333,21 @@@ impl Document
}
let stride = usize::try_from(p.columns).unwrap_or(usize::MAX).div_ceil(8).max(1);
let rows = u32::try_from(max / stride).unwrap_or(u32::MAX).min(height.unwrap_or(0));
- let data = undo(chain.split_last().map_or(&[][..], |(_, before)| before))?;
- pdfcraft_filters::decode_ccitt(&data, &p, rows).map_err(filter)
+ let data = undo(chain.split_last().map_or(&[][..], |(_, before)| before), work)?;
+ pdfcraft_filters::decode_ccitt_within(&data, &p, rows, work).map_err(filter)
}
+ /// The `/JBIG2Globals` stream a JBIG2 image `s` names by reference in its last filter's
+ /// `/DecodeParms`: `None` for a stream whose last filter isn't `JBIG2Decode`, or one without
+ /// globals. Redaction finds with it the other images that share a redacted image's globals.
+ pub fn jbig2_globals_ref(&self, s: &Stream) -> Option<ObjRef> {
+ let chain = s.readable_filters().ok()?;
+ if !matches!(chain.last(), Some((pdfcraft_filters::Filter::Jbig2, _))) {
+ return None;
+ }
+ self.last_filter_parms(s).get(b"JBIG2Globals").and_then(Object::as_ref)
+ }
+
/// What the `/JBIG2Globals` stream of JBIG2 image `s` (in its last filter's `/DecodeParms`)
/// decodes to, within [`MAX_JBIG2_GLOBALS`]; `None` without one (a reference to no object is
/// one to null, ISO 32000-2 §7.3.10, which is an absent entry, §7.3.7). The image is then read
diff --cc crates/redact/src/image.rs
index 52377078b,a96f4715e..67234497b
--- a/crates/redact/src/image.rs
+++ b/crates/redact/src/image.rs
@@@ -7,7 -8,7 +8,7 @@@
//! caller removes the whole image instead; that is fail-closed.
use pdfcraft_content::{Matrix, overlaps};
- use pdfcraft_cos::{Document, ImageBudget, Object, Stream};
-use pdfcraft_cos::{Dict, Document, Object, Stream};
++use pdfcraft_cos::{Dict, Document, ImageBudget, Object, Stream};
/// Most pixels an image may have to be cleared in place (larger ones are removed).
const MAX_PIXELS: u64 = 64 << 20;
diff --cc crates/redact/src/lib.rs
index 9ecca0a57,fad55c431..611745a42
--- a/crates/redact/src/lib.rs
+++ b/crates/redact/src/lib.rs
@@@ -70,10 -70,12 +70,16 @@@ pub enum RedactError
/// could not be shown complete.
#[error("the document's objects nest too deeply to remove hidden information completely; the operation was refused")]
TooDeep,
+ /// Past what one redaction may decode an image can't be cleared, and removing it whole would
+ /// take what no mark covers with it, unreported.
+ #[error("the images under these marks are more than one redaction can decode, so nothing was changed; redact fewer pages at a time")]
+ ImagesPastAllowance,
+ /// A JBIG2 image shares its `/JBIG2Globals` with a redacted one and can't be stored again
+ /// without them, so the shapes they hold, those of marks under the area included, would stay.
+ #[error(
+ "{0} JBIG2 image(s) share their symbol data with a redacted image and can't be decoded to be stored without it, so that data, which can show what is under the marks, would stay in the file; nothing was redacted"
+ )]
+ SharedJbig2Globals(usize),
#[error(transparent)]
Edit(#[from] pdfcraft_edit::EditError),
#[error(transparent)]