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", ], "", );