Repository navigation
Drop XML-illegal control characters from PDF/A XMP packet - #2827
Open
Silvertree2010 wants to merge 1 commit into
Open
Silvertree2010 wants to merge 1 commit into
Silvertree2010 wants to merge 1 commit into
Conversation
Found while testing crates/preflight/src/xmp.rs:37 Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ahmadmuj
reviewed
Oct 16, 2026
ahmadmuj
left a comment
There was a problem hiding this comment.
Checked XML 1.0 boundaries and exact values for all six Info fields with Expat after conversion, save, and reopen. Both PDF/A-2b and PDF/A-3b pass; the unchanged checks fail on the base. This checks the metadata XML, not full PDF/A conformance.
One local gate fails on the declared Rust 1.95 toolchain: cargo clippy -p pdfcraft-preflight -j 2 --lib --tests -- -D warnings reports nonminimal_bool at xmp.rs:41. The base passes; CI uses Rust 1.99.1. Could we replace the first clause with (*c >= '\u{20}' || matches!(c, '\t' | '\n' | '\r'))? This keeps the same character boundaries.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while testing
crates/preflight/src/xmp.rs:37(no existing issue): PDF/A conversion writes XML-illegal control characters from /Info into the XMP packet.Cause
xmp::esconly replaced & < > ", so C0 control characters in /Info values (Title, Author, Subject, Keywords, Producer, Creator) were copied into the XMP packet. XML 1.0 forbids those characters, so the packet was malformed and the PDF/A output invalid.Fix
xmp::escnow drops the characters XML 1.0 forbids before escaping. These are the C0 controls other than tab, LF and CR, plus U+FFFE and U+FFFF. This matchesexport::escandorganize::pdfx::esc. The regression test builds a document with control characters in each /Info field and checks the packet.Verified
xmp_packet_drops_xml_illegal_characters_from_info: fails onmainwithout the fix and passes with it (cargo test -p pdfcraft-preflight --lib xmp_packet_drops_xml_illegal_characters_from_info).cargo xtask cipasses.Not changed
DEL (U+007F) is legal in XML 1.0 and is still passed through. Reading XMP back (
unescape) and the other XMP fields are unchanged.🤖 Generated with Claude Code