From c7493ff6febbefe442a3ce39db94348ddaf05c55 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Tue, 3 Nov 2026 16:03:40 +0000 Subject: [PATCH] address review: cut only an over-long identifier; test with a filter that can't be read --- crates/preflight/src/lib.rs | 7 +++---- crates/preflight/src/tests.rs | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/preflight/src/lib.rs b/crates/preflight/src/lib.rs index e7c5499a53..05dcbe2910 100644 --- a/crates/preflight/src/lib.rs +++ b/crates/preflight/src/lib.rs @@ -194,12 +194,11 @@ pub fn declared(doc: &Document) -> Declared { .get(b"OutputConditionIdentifier") .and_then(|v| { doc.resolve(v).as_string().map(|s| { - // An even cut keeps UTF-16 text whole code units. - let n = s.bytes.len().min(MAX_IDENTIFIER_BYTES) & !1; - if n == s.bytes.len() { + if s.bytes.len() <= MAX_IDENTIFIER_BYTES { s.to_text() } else { - pdfcraft_cos::PdfString { bytes: s.bytes[..n].to_vec(), hex: s.hex }.to_text() + // An even cut keeps UTF-16 text whole code units. + pdfcraft_cos::PdfString { bytes: s.bytes[..MAX_IDENTIFIER_BYTES & !1].to_vec(), hex: s.hex }.to_text() } }) }) diff --git a/crates/preflight/src/tests.rs b/crates/preflight/src/tests.rs index 95c30942e4..a0588af7b1 100644 --- a/crates/preflight/src/tests.rs +++ b/crates/preflight/src/tests.rs @@ -541,7 +541,8 @@ fn convert_adds_no_srgb_intent_when_colour_could_not_all_be_read() { "<< /Type /Catalog /Pages 2 0 R >>", "<< /Type /Pages /Kids [3 0 R] /Count 1 /MediaBox [0 0 200 200] >>", "<< /Type /Page /Parent 2 0 R /Contents 4 0 R /Resources << >> >>", - "<< /Length 9 /Filter /FlateDecode >>\nstream\nnot flate\nendstream", + // A /Filter that isn't a name can't be decoded: the content isn't read. + "<< /Length 9 /Filter 5 >>\nstream\nnot flate\nendstream", ], "", );