Skip to content

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

fix(audit): keep the pending path across Q

aionggcc1086a86221
diff --git a/crates/audit/src/cover.rs b/crates/audit/src/cover.rs
index 3df666c19..20ed811d4 100644
--- a/crates/audit/src/cover.rs
+++ b/crates/audit/src/cover.rs
@@ -144,10 +144,11 @@ impl<'a> Walker<'a> {
match op.op.as_slice() {
b"q" => stack.push(gs.clone()),
b"Q" => {
+ // The current path is not graphics state (ISO 32000-2 §8.4.1): `re Q f` still
+ // fills the rectangle, whose corners are already in user space.
if let Some(g) = stack.pop() {
*gs = g;
}
- path = Path::Empty;
}
b"cm" => {
let before = gs.ctm;
diff --git a/crates/audit/src/tests.rs b/crates/audit/src/tests.rs
index 4ca3b0bf5..ded3a865c 100644
--- a/crates/audit/src/tests.rs
+++ b/crates/audit/src/tests.rs
@@ -592,3 +592,13 @@ fn reading_blocks_respect_stream_comments_and_split_operands() {
assert_eq!(text, "Replacement text", "{}", String::from_utf8_lossy(s1));
}
}
+
+/// The current path is not graphics state: a rectangle built before `Q` and filled after it
+/// paints the box, so it is a cover.
+#[test]
+fn rectangle_filled_after_restore_is_a_cover() {
+ let content = b"BT /F1 24 Tf 100 700 Td (SECRET DATA 123) Tj ET\n0 g\nq 100 688 220 32 re Q f\n";
+ let findings = audit_redactions(&open(one_page(content, ""))).expect("audit must run");
+ assert_eq!(findings.len(), 1, "{findings:?}");
+ assert!(findings[0].covered_text.contains("SECRET"), "{findings:?}");
+}