Skip to content

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

Closed

Description

@Tim81

Problem

PdfDocument builds the catalog in two places. (origin/main 1c61fa6,
src/VellumPdf.Kernel/Document/PdfDocument.cs.)

Entry Save path Signing path (WriteWithSignaturePlaceholders, :989)
Type, Pages, Metadata :835-838 :1277-1280
AcroForm only if non-null (:859-860) always, built just above (:1272-1281)
Outlines, PageMode :840-845 :1283-1288
MarkInfo :847-854 :1290-1296
StructTreeRoot :856-857 :1298-1299
OutputIntents from outputIntentsRef built earlier (:807-809, :862-863) built inline when Conformance != None (:1301-1304)
Lang ApplyLanguage (:865) ApplyLanguage (:1306)
DisplayDocTitle :867-872 :1308-1313

SaveAsync does not add a third copy: it runs Save on a buffer (:945-952). ApplyLanguage already exists as a
shared helper, and its comment says why: "Called from both the regular Save path and the signing placeholder path
so neither drifts out of sync" (:1758-1761).

Why it matters

Every new catalog entry in v2.4 has to go into both: /Names and /Dests (#241, #262), /PageLabels, the dual
pdfaid and pdfuaid XMP packet (#581), and ViewerPreferences. A missed copy is a signed document that
silently lacks an entry the unsigned one has.

Scope

  • Extract one private catalog builder that both paths call. Inputs the paths differ in (AcroForm, output intent
    reference) are parameters, not branches on which path called.
  • Pure refactor: the output of both paths stays byte-identical.
  • Document, in the builder's comment, which entries are conditional and why.

Acceptance

  • A golden test of the Save output and of the PrepareForSigning output for: a plain document, a tagged
    document, PDF/UA-1, PDF/A-2u, a document with bookmarks, and a document with a form field, with Timestamp pinned (PrepareForSigning reads
    Timestamp ?? DateTimeOffset.UtcNow too, PdfDocument.cs:1186, so an unpinned golden would not be stable). The bytes equal
    those of origin/main 1c61fa6 (hashes recorded before the refactor).
  • A test that adds a catalog entry through the builder and finds it in both outputs.
  • Reproducible output: two PdfDocument instances built identically with Timestamp pinned give equal sha256 for
    Save and for PrepareForSigning.
  • No public API change (PublicAPI.*.txt untouched).
  • Mutation: dropping DisplayDocTitle from the builder fails the PDF/UA-1 test in both paths.

Relates to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/conformanceenhancementtype/chore

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions