Repository navigation
test(kernel): pin the catalog bytes of Save and the signing path (part of #606) - #626
Merged
Merged
Conversation
Save and PrepareForSigning build the document catalog in two separate blocks that differ in key order (/AcroForm sits after /StructTreeRoot in one and straight after /Metadata in the other) and in when the output-intent objects are numbered. Merging them (#606) must not move a byte, so pin each path with the SHA-256 of the whole file and the exact catalog object text for plain, outline, tagged, PDF/A-2u, PDF/UA-1, form and outline + PDF/A-2u documents, plus the linearized and object-stream saves. Expected hashes are per target framework (net10.0 and net11.0 write an empty content stream differently); the catalog text is the same on both. Encrypted output cannot be hashed, so it is pinned structurally. Every file is also checked with qpdf.
…ange The golden hashes covered the raw bytes, which depend on the runtime's Deflate output, and CI floats the runtime patch. The hash now covers the file with every FlateDecode stream inflated and byte offsets masked, so one value serves both target frameworks, and the catalog text stays exact. Two configurations are added on both paths: one with every optional catalog key (outline, text field, PDF/UA-1, tagged, language) and one with a language and no conformance level, so that the position of /AcroForm and the condition on /Lang are both pinned.
… covers The /Prev mask also matched an outline item's /Prev N 0 R. It now skips an indirect reference. The remark and CHANGELOG name the linearization keys masked (/L /H /E /T) rather than all its numbers.
Rewrap thirteen comment lines that ran past the column limit. Wording is unchanged.
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.
Part of #606
Tests only, no production change, no public API change.
SaveandPrepareForSigningbuild the document catalog in two separate blocks ofPdfDocument. They do not agree:/AcroFormis written after/StructTreeRootbySave(and only when the document has form fields) and straight after/Metadataby the signing path (always, because it holds the signature field).Savereserves the output-intent objects before the outline tree; the signing path reserves them after it. A document with both an outline and a PDF/A claim therefore numbers/OutputIntentsdifferently on each path (8 0 R onSave, 12 0 R when signing, measured).#606 merges the two blocks into one builder. That change has to keep every byte, so this PR pins the bytes first, ahead of the refactor.
What is pinned
tests/VellumPdf.Kernel.Tests/CatalogGoldenTests.cs, withTimestampand (for signing)SignaturePlaceholderOptions.SigningTimepinned. Both pins are needed:Timestampalone leaves/Min the signature dictionary on the wall clock.SaveLanguage "en", text field,Language "en"with no conformance level, every optional key at once (outline + text field + PDF/UA-1 + tagged +Language "en"), outline + PDF/A-2u,Linearize,UseObjectStreamsSave, object streamsVellumPdf.Reader: keys in order (Type,Pages,Metadata) and every valueSave,Encrypt/U//Osalts and AES IVs come fromRandomNumberGeneratorwith no seam/Size//Root//Info//Encrypt, catalog read back with passworduPrepareForSigningLinearizeandUseObjectStreamsPrepareForSigningwithLinearize = trueEvery file also goes through
qpdf --check(the encrypted one with--password=u), asserting the line "No syntax or stream encoding errors found" and not only the exit code, throughExternalTool.TryRunsoOracleGateapplies. veraPDF is not used here: the catalog key order is not a veraPDF rule, so it would prove nothing about order; the refactor PR will use it for its own claim.The hash is taken over a normalised file, so it does not depend on the runtime's Deflate output. That output already differs between the two target frameworks: an empty page content stream is written as
/Filter /FlateDecode /Length 0with no data on net10.0 and as the 8 bytes of an empty zlib stream on net11.0. Normalising inflates every/FlateDecodestream (setting its/Lengthto the inflated length) and replaces what depends on a byte offset or a compressed size: the cross-reference entries,startxref, the trailer or cross-reference stream/Prevoffset (an outline item's/Prev N 0 Ris not masked), the linearization dictionary's/L,/H,/Eand/T(/Oand/Nstay pinned), and the contents of a hint stream and of a cross-reference stream. Object order, object numbers, every dictionary key and every stream's decoded content are still hashed, andqpdf --checkchecks the offsets in the same file. The catalog text is compared exactly and is not normalised. One hash per configuration serves both frameworks; I measured that by running the suite on net10.0 and net11.0, where all 20 values agreed.Not measured
Linux. The expected values were measured on Windows. This PR should not merge before CI is green on both target frameworks; if Linux hashes differ, that is a finding to report, not something to paper over with OS-keyed values.
Evidence the goldens discriminate
Mutations run against
src/VellumPdf.Kernel/Document/PdfDocument.cson the committed tests (rebuilt Kernel DLL each time, both target frameworks, same failing set on net10.0 and net11.0), restored withgit checkout -- src tests.Save_matchesTheGoldenBytesand the catalog-text test are writtenSave_*below; the two signing tests arePrepareForSigning_*./AcroFormafter/StructTreeRoot(theSaveposition)Save: reserve the output intents after the outline treeSave: write/AcroFormunconditionallyDisplayDocTitlefalse instead of trueSave:/AcroFormstraight after/Metadata(the signing order)Save_*foreverything(hash and catalog text)Save:/AcroFormlast, after/ViewerPreferencesSave_*foreverythingSave:/AcroFormafter/OutputIntents, before/LangSave_*foreverything/Langwritten only under PDF/UA-1Save:/Pagesand/MetadataswappedSave_matchesTheGoldenBytes(objstm): that catalog is inside a compressed stream, so this shows the normalised hash still covers decoded stream contentSaveexpected hash changedSave_matchesTheGoldenBytes(plain), with the computed hash in the messageWithout the
everythingconfiguration the three/AcroFormposition mutants (straight after/Metadata, last, after/OutputIntents) survive onSave: no other configuration holds an outline or tagging or a conformance claim together with a form. Withoutlang, the/Langcondition survives.Test counts
dotnet test tests/VellumPdf.Kernel.Tests -c ReleasewithREQUIRE_ORACLES=1,REQUIRE_VERAPDF=1, veraPDF 1.30.4, qpdf 12.4.2, poppler onPOPPLER_HOME, on this branch merged with main b563dae: net10.0 1,762 passed, net11.0 1,762 passed, 0 failed, 0 skipped.CatalogGoldenTestsis 63 of each. Also clean:dotnet build VellumPdf.slnx -c Release(0 warnings),dotnet format --verify-no-changes,eng/clean-room-check.ps1,python eng/generate-roadmap.py --check.Not done
PdfDocument.cs, which Harden Layout and Kernel inputs and the save lifecycle (v2.3.4, v2.3.5); read JBIG2 file headers; keep narrow no-break spaces #571 also changes.Added, as the tests-only test(layout): pin the boundaries the documentation states #553 had.VellumPdf.Kernel.Tests.csproj(Harden Layout and Kernel inputs and the save lifecycle (v2.3.4, v2.3.5); read JBIG2 file headers; keep narrow no-break spaces #571 changes it); the new file is picked up by the default glob.