fix(pdf): reach deterministic output from the multi-section path, harden the /ID#364
Merged
Merged
Conversation
…den the /ID
Three follow-ups to the deterministic() backend option:
- MultiSectionDocument hard-wired its own default backend, so a configured
PdfFixedLayoutBackend could not reach the section path through the public
API. Add toPdfBytes(FixedLayoutRenderer) and
writePdf(FixedLayoutRenderer, OutputStream) overloads — the multi-section
counterpart of DocumentSession.render(backend); the no-arg methods delegate
to them with the built-in default.
- The /ID seed only covered five info fields joined with spaces, so keywords
and custom metadata were ignored and shifted field boundaries could collide
("A B"+"" vs "A"+"B"). Derive it from the complete info dictionary as
sorted, length-prefixed key/value frames hashed with SHA-256 (first 16
bytes).
- deterministic(Instant) now truncates to whole seconds up front — PDF dates
carry second precision, so a sub-second instant previously pinned a
second-precision date while the /ID used the full-precision value.
New coverage: multi-section byte-identity through GraphCompose.documents(),
sub-second truncation equivalence, field-boundary collision and
keywords/custom-field participation in the /ID.
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.
Why
Review follow-ups to the reproducible-output option (#363):
MultiSectionDocumentbuilds its own default backend internally, so a user could notpass
PdfFixedLayoutBackend.builder().deterministic(true).build()to the section path —the internal wiring existed, but the public
GraphCompose.documents()surface had no wayto reach it.
/IDseed covered only five info fields joined with spaces: keywords and custommetadata did not participate, and shifted field boundaries collided
(
title="A B", author=""vstitle="A", author="B").deterministic(Instant)kept sub-second precision: PDF dates serialize to whole seconds,so a sub-second instant pinned a second-precision CreationDate while the
/IDwas derivedfrom the full-precision value.
What
MultiSectionDocument.toPdfBytes(FixedLayoutRenderer)andwritePdf(FixedLayoutRenderer, OutputStream)— the multi-section counterpart ofDocumentSession.render(backend); the existing no-arg methods delegate to them with thebuilt-in default, so current callers are unchanged. PDF-specific configuration stays out of
the core API (the parameter is the existing
FixedLayoutRendererseam).PdfDeterminismWriter.documentIdnow canonicalizes the complete info dictionary —every entry participates, as sorted, length-prefixed key/value frames — hashed with
SHA-256, truncated to the 16 bytes a PDF
/IDcarries.Builder.deterministic(Instant)truncates to whole seconds up front, so the serializeddates and the
/IDderive from the same value.Tests
PdfDeterministicOutputTest(6): + multi-section byte-identity through the publicGraphCompose.documents()path, + sub-second instant renders byte-identically to itswhole-second truncation.
PdfDeterminismWriterTest(6): + field-boundary collision stays distinct, + keywords andcustom metadata fields participate in the
/ID../mvnw -f aggregator/pom.xml verify -pl :graph-compose-qa -am— full compile + javadocgate + the qa visual/parity suite (643): green.
The
/IDscheme change is safe pre-release:deterministic(...)is@Betaand unpublished.