You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Kernel: a text string with a control code that PDFDocEncoding leaves undefined is written as that one byte #778
ISO 32000-1, 7.9.2.2 (ISO 32000-2, 7.9.2.2.1): a text string "shall be" encoded in PDFDocEncoding or UTF-16BE (and, in PDF 2.0, UTF-8). Annex D.3 of both marks the codes 0x00 to 0x08, 0x0B, 0x0C, 0x0E to 0x17, 0x7F, 0x9F and 0xAD undefined in PDFDocEncoding (ISO 32000-2, Table D.3, "U" in the Notes column; the 32000-1 table agrees).
PdfLiteralString.FromTextString (PdfLiteralString.cs) takes the one-byte form for any character below U+0018. Its remarks say so: "The undefined ones, such as U+0001, stay one byte: the table gives those bytes no other character". It sends U+007F, U+009F and U+00AD to UTF-16BE, so it treats three of the undefined codes as undefined and the fifteen below U+0018 as fine.
Measured on origin/main b2791ba, no claim, AddCheckBox(page, "a\u0001b", rect) then Save: /T is the bytes 61 01 62 (no byte order mark). A string made only of defined codes, and one holding U+0018 to U+001F, U+007F, U+0080 to U+00A0 or U+00AD, takes the UTF-16BE form (measured: FE FF 00 78 00 18 00 79 for x U+0018 y).
Sweep: FromTextString has seven call sites (git grep "FromTextString(" origin/main -- src): the four signature dictionary strings (Name, Reason, Location, ContactInfo), the output intent's OutputConditionIdentifier and Info (PdfDocument.cs), and the form's TextString helper, which writes /T, /V, /Opt and /MK /CA (AcroFormBuilder.cs). No other package writes a text string through it. FromUnicode, the other encoder, writes UTF-16BE for everything and is #738's.
Proposal
Take the UTF-16BE form for every code Table D.3 marks undefined, as FromTextString already does for U+007F, U+009F and U+00AD. The bytes change only for a string with one of those controls; every other string keeps its bytes. Update the remarks of FromTextString and the "no character is rewritten" paragraph of PdfSignatureSettings.SignerName, Reason, Location, ContactInfo and PdfDocument.AddTextField, which list U+0000 to U+0017 as written one byte per character.
Acceptance
The skipped test ConformanceAuditG6Tests.Iso32000_1_7_9_2_2_ATextStringHoldsNoCodePDFDocEncodingLeavesUndefined runs and passes, and the pin Iso32000_1_7_9_2_2_PinsTodayAControlCodePDFDocEncodingLeavesUndefinedIsWrittenAsOneByte is replaced.
The known-answer test Iso32000_1_7_9_2_2_FieldNamesAreTextStringsInPdfDocEncodingOrUtf16Be still passes.
Activity
test: pin form and signature field output to its ISO clauses (#779)