Skip to content

refactor(kernel): build the catalog once for Save and the signing path (#606) - #635

Merged
Tim81 merged 3 commits into
mainfrom
refactor/shared-catalog-builder
Nov 20, 2026
Merged

Tim81 merged 3 commits into
mainfrom
refactor/shared-catalog-builder

Conversation

@Tim81

@Tim81 Tim81 commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Closes #606

PdfDocument.Save and the signing path (PrepareForSigning) each assembled the catalog in their own
block, and the two blocks disagreed on key order and on where the output-intent objects are numbered.
One private BuildCatalog(CatalogParts) now writes the keys. It reserves nothing and calls nothing
that reserves; each path computes its references where it did before and passes them in.

  • AcroFormFollowsMetadata is a parameter, not a branch on the caller: Save writes /AcroForm after
    the last of /Outlines+/PageMode, /MarkInfo and /StructTreeRoot that is present, the signing path
    right after /Metadata. It exists only for byte identity.
  • The signing path calls BuildOutputIntents immediately before the builder, which keeps the object
    numbers of the old inline call.
  • _written = true and every refusal stay where they were. The builder throws nothing.
  • Internal test seam PdfDocument.CatalogExtraEntries (null by default): entries are appended after
    every other key on both paths. No public API change.

No output changes. The 63 CatalogGoldenTests cases from #626 pass with their expected values
untouched; nine tests are added to that class (seam on both paths and through an object stream, and a
retry after a precondition refusal on each path, compared with the golden hash), and a form-pdfa2u
configuration (a text field under untagged PDF/A-2u) is added to the Save and signing tables, six more
cases. Its hashes and catalog text were recorded from main at 2027421 and the branch gives the same.

Gates (Release, REQUIRE_ORACLES=1, qpdf 12.4.2, veraPDF 1.30.4)

Project net10.0 + net11.0 total failed skipped
Kernel.Tests (includes the signing tests) 4742 0 0
Layout.Tests 2082 0 4
Reader.Tests 4046 0 24

Build 0 warnings; dotnet format --verify-no-changes, eng/clean-room-check.ps1 and
generate-roadmap.py --check pass. The Layout and Reader skips are not from a missing oracle, which
fails under REQUIRE_ORACLES; I did not trace them.

Mutations (net10.0, rebuilt DLL each time, source restored afterwards)

Mutant Failing tests (of 72 in the class; m7 ran against the 78 of the final head)
m1: drop DisplayDocTitle 10: pdfua1 and everything, Save and Sign, hash and text, plus the seam test for everything
m2: signing passes AcroFormFollowsMetadata: false 15: Sign hash/text for outline, tagged, pdfa2u, pdfua1, everything, outline-pdfa2u; two seam tests; the Sign retry test
m3: signing reserves output intents before the outline tree 7: Sign hash/text, seam and retry for outline-pdfa2u and everything
m4: Save writes an empty /AcroForm when there is none 23: 9 Save hashes, 9 text cases, objstm key order, encryption, two seam tests, the Save retry test
m5: delete the seam's copy loop 7: the seam tests
m7: /OutputIntents before a late /AcroForm, only when untagged 2: Save hash and Save catalog text for form-pdfa2u; no other case fails, which is why the configuration was needed
m6: MarkInfo after StructTreeRoot 14: tagged, pdfua1, everything, both paths, hash and text, plus two seam tests

Not run: a veraPDF --flavour 2u case; the class has none and the key order is not what veraPDF checks.

…#606)

Save and the signing path assembled the catalog in separate blocks that
disagreed on key order and on where the output-intent objects are
numbered. One builder now writes the keys from references each path has
already reserved, so no output changes and no refusal moves. A test seam
lets the catalog parts that later issues add be checked on both paths.
…atalog comments

No golden had form fields under an untagged PDF/A level, so a builder that
wrote /OutputIntents before a late /AcroForm only for an untagged document
passed every case. form-pdfa2u adds one to the Save and signing tables; the
values were recorded from main and the branch gives the same ones.

The catalog builder comments now state what holds today, name the actual
/AcroForm placement rule, scope the seam's claim to the pinned
configurations, and list PDF/UA-1 and the CMYK output intent where the
carried-over comments left them out.
@Tim81
Tim81 merged commit ec2547d into main Nov 20, 2026
4 checks passed
@Tim81
Tim81 deleted the refactor/shared-catalog-builder branch November 21, 2026 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kernel: the catalog is built twice, in Save and in the signing path, and the two copies drift

1 participant