Repository navigation
fix(kernel): write whole reals outside int32 as reals, and form text as text strings - #646
Merged
Merged
Conversation
PdfReal, the canvas operands and the AcroForm appearance numbers wrote 2147483648.0 as the integer token 2147483648. ISO 32000-2 Table C.1 gives integers 32 bits and ISO 19005-2 6.1.13 fails a PDF/A file past that range; from 2^63 up a reader drops the object. One shared formatter now appends .0 when the written text is whole and not a 32-bit integer.
AcroFormBuilder.TextString wrote Latin-1 bytes for any string without a character above U+00FF, which a PDFDocEncoding reader decodes as other characters for U+0018-U+001F, U+007F, U+0080-U+00A0, U+00AD and a leading byte order mark. It now uses PdfLiteralString.FromTextString, as the signing strings do. The public documentation states the rule and the exceptions Save raises.
Saves PDF/A-2u documents with link and canvas numbers at 2147483648, -2147483649, 3.403e38 and 3e9, asserts the real token is in the file, and asserts veraPDF lists no failed rule. Without the suffix veraPDF fails 6.1.13-1 on each. A form with a U+00A0 name fails the same 6.2.11.4.1-1 as an ASCII one, so veraPDF cannot see the text-string change. Also corrects two phrases in the #639 CHANGELOG entry.
…umber site The integer bound is ISO 32000-1 Table C.1; ISO 32000-2 says only that integers can often be expressed within 32 bits. The #641 entry now excepts U+001B and the byte order mark, SaveAsync documents the WinAnsi refusal under ArgumentException, and the TextString summary names the encoders that really share it. New tests kill a plain-format mutant of each of the 12 appearance-stream number sites.
…orm-text # Conflicts: # CHANGELOG.md
This was referenced Nov 21, 2026
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.
Closes #639
Closes #641
Two object-writer encoding fixes with disjoint documents (numbers, form text strings), kept as two commits.
#639: a whole number outside the 32-bit range is a real token
PdfReal.WriteTo,PdfCanvas.Nand the twelve{0:0.###}appearance-stream sites plusBuildDainAcroFormBuilderformatted a whole value with no decimal point, so 2147483648.0 reached the file asthe integer token
2147483648. ISO 32000-1 Table C.1 gives 2,147,483,647 as the largest integer (ISO 32000-2 Table C.1 says only thatintegers "can often be expressed within 32 bits"), and ISO 19005-2 6.1.13 fails a PDF/A file with an
integer outside that range; from 2^63 up,
qpdf --checkdrops the object.The change is one internal formatter,
PdfNumberFormat, used by all three. It decides on the writtentext, not on the double: if the text has no
.and does not parse as anint, it appends.0.(
.alone is also valid 7.3.3 syntax;.0was chosen to read as a real at a glance. No readerbehaviour is claimed for that choice.) NaN and infinity refusals stay where they were. Every site
is a number-typed slot (
/XYZcoordinates, rectangles, shading arrays, alpha, colours, them,l,c,re,Td,Tm,Tf,w,cmand colour operands), so 7.3.3's "a real shall not be presentwhen an integer is expected" is not engaged.
NamedDestinationTablekeeps its +-2,147,483,647 bound with its comment rewritten (the old reason isfalse after this change; the table is internal and has no caller in
src).Deliberate output change: only tokens whose rounded text is a whole number outside -2^31..2^31-1
change. See the CHANGELOG entry.
#641: AcroFormBuilder.TextString uses PdfLiteralString.FromTextString
Field names, values, options, selected option and captions (
/T,/V,/Opt,/MK /CA) go throughthe same encoder as every other text string. XML docs on the five
Add*methods state the rule onceon
AddTextField, with the lone-surrogate and U+001B "Do not pass" naming 3.0, andSave,SaveAsyncandPrepareForSigninglist theArgumentExceptionfor a drawn value outsideWinAnsiEncoding. The appearance-stream mapping is unchanged.
Tests
RealTokenTests(token table throughPdfReal, canvasm, link/Dest, outline/Dest,/MediaBox, form/Rect,/BBox, appearance and/DA; qpdf--checkand--json), and newFormTestsrows for each site and for the appearance byte.Mutations
Each applied to the commit named, run against the new test class only (net10.0), then reverted.
Math.Abs(value) > int.MaxValue)-2147483648and2147483647.000001rows through link, outline, MediaBox, canvas)Nwithout the suffixCanvasOperandrow outside int32)long.TryParse.instead of.0{0:0.###}c > 0xFFtestFE FFmark check inFromTextStringFromUnicode/Opton the old encoderChoiceField_options_are_written_as_text_strings)Per-site coverage of the AcroForm appearance numbers: for each of the 12
Num(...)lines inAcroFormBuilder(check box, radio, push button and text field), replacing that one line with the plain0.###format fails exactly one new or existing test inRealTokenTests(12 of 12 sites killed; the pushbutton
re Sline and the text fieldre SandTdlines were not killed before the added tests).Gates
Release, 0 warnings on
VellumPdf.slnx;dotnet format --verify-no-changes, the clean-room check andgenerate-roadmap.py --checkpass. Tests on net10.0 and net11.0 with the oracles required: Kernel 2,476(0 failed, 0 skipped on both), Layout 1,074 (2 skipped), Reader 2,023 (12 skipped), Conformance 1,453,
Barcodes 1,051 (0 failed in all). The Layout, Reader, Conformance and Barcodes counts were taken one commit
earlier; the last commit adds one test file and touches no source in those projects.
veraPDF
RealTokenVeraPdfTestssaves a PDF/A-2u document with a link destination and canvasmoperand at2147483648, -2147483649, 3.403e38 and 3e9, first asserts the file holds the
N.0token, then assertsveraPDF 1.30.4 (flavour 2u) lists no failed rule. It reads the failed rules from the report, not the exit
code.
Direction, measured on the same four fixtures plus 3.5e38:
.0suffix (the old behaviour)A form is different: a text field draws with the non-embedded Helvetica, so every PDF/A-2u form fails
6.2.11.4.1-1 once, with an ASCII name and with a U+00A0 name alike. The form test therefore asserts the two
failed-rule lists are equal and that
/Tand/Vhold the UTF-16BE strings. veraPDF 1.30.4 has no rulethat tells the old single byte 0xA0 from the new string, so that test cannot discriminate the encoding
change; the byte-exact
FormTestsrows do.Differential against 2.3.3
28,631 rows compared at the base commit and at this branch's head. The base shows no violation. The head
shows 36 rows whose files equal 2.3.3's once the
N.0tokens outside int32 are turned back into integertokens and the length, offset, date and ID fields are masked, and five rows still reported as output
changes. Those five combine this change with one already on the base:
2.3.3's file for the same plan with U+00A0 in place of those characters.
head's file equals the base head's file for that row.
Every other row has the verdict it had at the base, with one exception that is not this change: a
cancellation-timing row (a save cancelled partway) went from identical to deliberate between the two runs,
because whether the cancel lands before or after serialisation depends on timing.