Skip to content

test(reader): add a third-party PDF fixture corpus - #205

Merged
Tim81 merged 4 commits into
mainfrom
feat/196-third-party-fixtures
Aug 20, 2026
Merged

Tim81 merged 4 commits into
mainfrom
feat/196-third-party-fixtures

Conversation

@Tim81

@Tim81 Tim81 commented Aug 20, 2026 •

Copy link
Copy Markdown
Owner

Closes #196. Test-only: no src/ behaviour change, no public API change.

Why

Every PDF in the tree came from VellumPdf's own writer, which only ever emits generation 0, never a
hybrid-reference file, never another producer's object-stream layout. Three defects in the #121 review
shared that root cause, and each was caught only because a reviewer hand-built the adversarial file.

The corpus

Twelve fixtures, each SHA-256-pinned by a guard test and exercised by a behaviour test.

Fixture Producer Pins
hybrid-spec-convention.pdf hand-built ISO 32000-2 §7.5.8.4's hiding arrangement: object freed in revision 1, defined via revision 2's /XRefStm
hybrid-samesection-undefined.pdf hand-built The same shape within one revision — the open question in pdf-association/pdf-issues#237
freed-object-reuse.pdf hand-built Object 5 live at gen 0, freed with next-gen 1, reused as 5 1 obj across three revisions
objstm-xrefstream.pdf qpdf --object-streams=generate Object streams plus a cross-reference stream, no classic table
linearized.pdf qpdf --linearize /Linearized
incremental-update.pdf poppler pdfattach A real appended revision: two %%EOF, /Prev, byte-identical prefix
nonzero-gen-base.pdf / nonzero-generation.pdf hand-built / pdfattach A non-zero generation read from a document, and one surviving an append
truncated-tail.pdf, broken-startxref.pdf corrupted baseline Must throw InvalidDataException
length-mismatch.pdf hand-built /Length 64 on a 46-byte body; the /Length-preferred branch must verify endstream follows and fall back
baseline.pdf qpdf The qpdf-normalised fixed point the derived fixtures are measured against

What three reviewers changed

Fixture integrity and test rigour came back sound: all twelve digests correct, every structural property
verified at byte level, every provenance command reproducible, no licensing or clean-room exposure. All
20 behaviour tests die to a targeted reader regression, and a 76,454-variant hostile sweep over the
fixtures produced no exception outside InvalidDataException / UnsupportedPdfFeatureException.

Almost every defect was in what the prose claimed, and the fixes make this PR claim less than it did:

  • A coverage guard that degraded silently. Excluding resource names containing / is a blocklist: a
    future Fixtures/Extra/ corpus using the same folder-qualified pattern this PR introduces shipped
    completely uncovered with the suite green. Proven, then narrowed to a ThirdParty/ prefix so any new
    prefix fails loudly.
  • A citation that did not say what it was cited for. The same-section hybrid case was attributed to
    pdf-issues#146, a Table 19 wording erratum that never mentions it. The on-point reference is Encryption: PDF MAC integrity protection (ISO/TS 32004) #237, open
    and labelled bug — where the question of which entry wins is explicitly unresolved. The prose no
    longer presents the construct as a void the spec left blank, and does not claim anyone has settled it.
  • A self-citation dressed as corroboration. The README credited qpdf with a comment that lives in
    PdfObjectParser.cs — our own source.
  • Two overstated oracles. poppler was described as confirming the hidden object; it only shows the
    surrounding page survives, and it reads xref streams so it is no stand-in for a PDF 1.4 consumer.
  • A body length that was wrong. 41 bytes was copied from another fixture; it is 46, and qpdf's
    recovered stream length: 46 now backs it.
  • A test whose documentation named the wrong mechanism. LengthMismatch_recoversTheFullStreamBody
    survives a mutation that destroys ScanToEndstream's tiering, because the fixture holds one
    endstream. It pins the /Length fallback rule, and now says so.

Two honest reframings, both narrowing the claim:

  • This closes a dialect-confidence gap, not a hole in the reader's logic. A reviewer could not isolate
    a regression only these files catch — every mutation also killed a pre-existing synthetic test. That
    is the stated purpose (confirming the same mechanisms against another producer's dialect), but the PR
    should not read as more.
  • freed-object-reuse.pdf adds an axis, not discrimination. Removing deletion tracking kills two
    existing GenerationNumberTests and not the new test: revision 3's definition wins regardless, so the
    deletion is never load-bearing. It pins correct end-to-end behaviour on a real three-revision document.
    The README says this plainly.

One pre-existing defect fixed in passing

XrefParser.cs has pointed at "PR #193's xref-rebuild fallback" since it was written. #193 shipped the
/Encrypt-in-XRefStm detection and the endstream hardening; reconstruction is #184, still open. Same
failure as the #146 citation above, found by looking for more of them.

Verification

Full solution with REQUIRE_VERAPDF=1 and REQUIRE_BARCODE_ORACLE=1: 4914 passed, 0 failed, 0
skipped
(Reader.Tests 233 → 272). dotnet format --verify-no-changes clean, clean-room-check.ps1
passes, AOT smoke passes, no tab bytes, no PublicAPI change, no released CHANGELOG section altered.

Every reader fixture before this one came from VellumPdf's own writer,
which only emits generation 0 and never a hybrid-reference file or
another producer's object-stream layout. The #121 review found three
defects that trace to exactly that gap, each caught only because a
reviewer hand-built the adversarial fixture during review.

Sourced from qpdf and poppler where a tool can produce the shape,
hand-built where none can. Covers object streams, cross-reference
streams, linearization, a genuine incremental update, a nonzero-
generation catalog surviving both a read and an appended revision, and
three damaged-file shapes. One hybrid fixture pins ISO 32000-2
7.5.8.4's documented convention, confirmed against qpdf and poppler as
independent oracles; a related fixture puts the same free-then-
redefine shape in a single revision, which the spec does not describe,
and is documented as pinning current behavior rather than conformance.

Also scopes EncryptedFixtureCorpusTests's embedded-resource coverage
scan to the flat-named Encrypted set, now that a second, folder-
qualified fixture corpus shares the same test assembly.
Adds the 12th third-party fixture (freed-object-reuse.pdf) and its three
behaviour tests, plus fixes for a three-reviewer pass on #205: the
EveryEmbeddedFixture_isCoveredByTheTheory guard was an open-ended
slash-blocklist that a future folder-qualified corpus could slip past
silently, narrowed to name the one known "ThirdParty/" prefix instead.

The rest is prose accuracy on a corpus whose bytes and tests were already
sound. Wrong citation (pdf-issues#146, a closed Table 19 wording erratum,
corrected to the actual open issue on this construct, #237); a VellumPdf
source comment misattributed to qpdf; a mismeasured /Length body size (41
bytes, corrected to the qpdf-arbitrated 46); a false qpdf/poppler oracle
claim for the hidden-object fixture, where poppler's rendered output shows
the page survives but says nothing about the object itself; false causality
in the CHANGELOG's qpdf-can't-build-hybrid-files claim; an overclaimed
AppendRevision gap that this PR's fixture never calls; and a baseline.pdf
fixture never actually opened by a reader test.

The corpus's own overall framing gets corrected too: mutation testing found
every mutation it could construct also killed a pre-existing synthetic
test, so this closes a dialect-confidence gap, not a logic gap in the
reader -- and the freed-object-reuse fixture's own test doesn't add
discrimination beyond GenerationNumberTests, which the README now says
plainly instead of implying otherwise.
The comment above `freed` said PR #193's xref-rebuild fallback would be the
natural home for recovering a spuriously-freed object. #193 shipped the
/Encrypt-in-XRefStm detection and the endstream hardening; it has no rebuild
fallback. Reconstruction is #184, still open.

Found while fixing the same defect class in the #196 corpus, where a comment
cited a Table 19 wording erratum for a question that erratum does not address.
A citation nobody can follow is worse than none — it spends the reader's trust
before they reach the part that is right.
@Tim81
Tim81 force-pushed the feat/196-third-party-fixtures branch from 9313fda to 3003036 Compare August 20, 2026 09:16
The reuse half of freed-object-reuse.pdf could not fail: revision 3 defines
5 1 obj, so it resolves whether or not revision 2's deletion was recorded.
Add object 7, freed in revision 2 and never redefined, where returning null
requires having honoured the free entry. Removing freed.UnionWith(localFreed)
now fails the test; before, it passed. qpdf discriminates here too, and the
revision-2 free list is linked per ISO 32000-2 §7.5.4.

Ask for the stale generation before the cache is warm. Resolving 5 1 first
cached object 5 at generation 1, so the 5 0 lookup exited on the cached value
without reaching the resolution path at all.

Five claims were wrong:

- The docs said an xref entry's generation must match the object header.
  Resolve never reads the header's generation when the xref is authoritative;
  rewriting 5 1 obj's header to 7 leaves the test green. The rule is that the
  reference's generation must match the entry's.
- The note on BrokenStartxref said the test failing once #184 lands would be a
  success signal. #197 is opt-in and defaults off, so it keeps passing — a
  failure would be the regression the note told a maintainer to wave through.
- qpdf returning null for object 5 was attributed to the deletion. A control
  with no free entry anywhere gives identical answers; it comes from the merged
  xref. Object 7 is where qpdf actually discriminates.
- The same-section hybrid case was described as unsettled "expert opinion
  included". Three participants in pdf-issues#237 lean the other way and none
  supports our reading. Say so, and that we differ deliberately (#206).
- One file still credited poppler with resolving the hidden object, retracted
  elsewhere in the previous pass.
@Tim81
Tim81 force-pushed the feat/196-third-party-fixtures branch from 3003036 to 6f8de7a Compare August 20, 2026 09:16
@Tim81
Tim81 merged commit 2f8a13d into main Aug 20, 2026
3 checks passed
@Tim81
Tim81 deleted the feat/196-third-party-fixtures branch August 28, 2026 14:40
Tim81 added a commit that referenced this pull request Sep 6, 2026
* test(reader): add a third-party PDF fixture corpus (#196)

Every reader fixture before this one came from VellumPdf's own writer,
which only emits generation 0 and never a hybrid-reference file or
another producer's object-stream layout. The #121 review found three
defects that trace to exactly that gap, each caught only because a
reviewer hand-built the adversarial fixture during review.

Sourced from qpdf and poppler where a tool can produce the shape,
hand-built where none can. Covers object streams, cross-reference
streams, linearization, a genuine incremental update, a nonzero-
generation catalog surviving both a read and an appended revision, and
three damaged-file shapes. One hybrid fixture pins ISO 32000-2
7.5.8.4's documented convention, confirmed against qpdf and poppler as
independent oracles; a related fixture puts the same free-then-
redefine shape in a single revision, which the spec does not describe,
and is documented as pinning current behavior rather than conformance.

Also scopes EncryptedFixtureCorpusTests's embedded-resource coverage
scan to the flat-named Encrypted set, now that a second, folder-
qualified fixture corpus shares the same test assembly.

* test(reader): add freed-object-reuse fixture, fix #196 review claims

Adds the 12th third-party fixture (freed-object-reuse.pdf) and its three
behaviour tests, plus fixes for a three-reviewer pass on #205: the
EveryEmbeddedFixture_isCoveredByTheTheory guard was an open-ended
slash-blocklist that a future folder-qualified corpus could slip past
silently, narrowed to name the one known "ThirdParty/" prefix instead.

The rest is prose accuracy on a corpus whose bytes and tests were already
sound. Wrong citation (pdf-issues#146, a closed Table 19 wording erratum,
corrected to the actual open issue on this construct, #237); a VellumPdf
source comment misattributed to qpdf; a mismeasured /Length body size (41
bytes, corrected to the qpdf-arbitrated 46); a false qpdf/poppler oracle
claim for the hidden-object fixture, where poppler's rendered output shows
the page survives but says nothing about the object itself; false causality
in the CHANGELOG's qpdf-can't-build-hybrid-files claim; an overclaimed
AppendRevision gap that this PR's fixture never calls; and a baseline.pdf
fixture never actually opened by a reader test.

The corpus's own overall framing gets corrected too: mutation testing found
every mutation it could construct also killed a pre-existing synthetic
test, so this closes a dialect-confidence gap, not a logic gap in the
reader -- and the freed-object-reuse fixture's own test doesn't add
discrimination beyond GenerationNumberTests, which the README now says
plainly instead of implying otherwise.

* docs(reader): point the rebuild-fallback note at the right issue

The comment above `freed` said PR #193's xref-rebuild fallback would be the
natural home for recovering a spuriously-freed object. #193 shipped the
/Encrypt-in-XRefStm detection and the endstream hardening; it has no rebuild
fallback. Reconstruction is #184, still open.

Found while fixing the same defect class in the #196 corpus, where a comment
cited a Table 19 wording erratum for a question that erratum does not address.
A citation nobody can follow is worse than none — it spends the reader's trust
before they reach the part that is right.

* test(reader): make the freed-object deletion load-bearing

The reuse half of freed-object-reuse.pdf could not fail: revision 3 defines
5 1 obj, so it resolves whether or not revision 2's deletion was recorded.
Add object 7, freed in revision 2 and never redefined, where returning null
requires having honoured the free entry. Removing freed.UnionWith(localFreed)
now fails the test; before, it passed. qpdf discriminates here too, and the
revision-2 free list is linked per ISO 32000-2 §7.5.4.

Ask for the stale generation before the cache is warm. Resolving 5 1 first
cached object 5 at generation 1, so the 5 0 lookup exited on the cached value
without reaching the resolution path at all.

Five claims were wrong:

- The docs said an xref entry's generation must match the object header.
  Resolve never reads the header's generation when the xref is authoritative;
  rewriting 5 1 obj's header to 7 leaves the test green. The rule is that the
  reference's generation must match the entry's.
- The note on BrokenStartxref said the test failing once #184 lands would be a
  success signal. #197 is opt-in and defaults off, so it keeps passing — a
  failure would be the regression the note told a maintainer to wave through.
- qpdf returning null for object 5 was attributed to the deletion. A control
  with no free entry anywhere gives identical answers; it comes from the merged
  xref. Object 7 is where qpdf actually discriminates.
- The same-section hybrid case was described as unsettled "expert opinion
  included". Three participants in pdf-issues#237 lean the other way and none
  supports our reading. Say so, and that we differ deliberately (#206).
- One file still credited poppler with resolving the hidden object, retracted
  elsewhere in the previous pass.
Tim81 added a commit that referenced this pull request Sep 6, 2026
* test(reader): add a third-party PDF fixture corpus (#196)

Every reader fixture before this one came from VellumPdf's own writer,
which only emits generation 0 and never a hybrid-reference file or
another producer's object-stream layout. The #121 review found three
defects that trace to exactly that gap, each caught only because a
reviewer hand-built the adversarial fixture during review.

Sourced from qpdf and poppler where a tool can produce the shape,
hand-built where none can. Covers object streams, cross-reference
streams, linearization, a genuine incremental update, a nonzero-
generation catalog surviving both a read and an appended revision, and
three damaged-file shapes. One hybrid fixture pins ISO 32000-2
7.5.8.4's documented convention, confirmed against qpdf and poppler as
independent oracles; a related fixture puts the same free-then-
redefine shape in a single revision, which the spec does not describe,
and is documented as pinning current behavior rather than conformance.

Also scopes EncryptedFixtureCorpusTests's embedded-resource coverage
scan to the flat-named Encrypted set, now that a second, folder-
qualified fixture corpus shares the same test assembly.

* test(reader): add freed-object-reuse fixture, fix #196 review claims

Adds the 12th third-party fixture (freed-object-reuse.pdf) and its three
behaviour tests, plus fixes for a three-reviewer pass on #205: the
EveryEmbeddedFixture_isCoveredByTheTheory guard was an open-ended
slash-blocklist that a future folder-qualified corpus could slip past
silently, narrowed to name the one known "ThirdParty/" prefix instead.

The rest is prose accuracy on a corpus whose bytes and tests were already
sound. Wrong citation (pdf-issues#146, a closed Table 19 wording erratum,
corrected to the actual open issue on this construct, #237); a VellumPdf
source comment misattributed to qpdf; a mismeasured /Length body size (41
bytes, corrected to the qpdf-arbitrated 46); a false qpdf/poppler oracle
claim for the hidden-object fixture, where poppler's rendered output shows
the page survives but says nothing about the object itself; false causality
in the CHANGELOG's qpdf-can't-build-hybrid-files claim; an overclaimed
AppendRevision gap that this PR's fixture never calls; and a baseline.pdf
fixture never actually opened by a reader test.

The corpus's own overall framing gets corrected too: mutation testing found
every mutation it could construct also killed a pre-existing synthetic
test, so this closes a dialect-confidence gap, not a logic gap in the
reader -- and the freed-object-reuse fixture's own test doesn't add
discrimination beyond GenerationNumberTests, which the README now says
plainly instead of implying otherwise.

* docs(reader): point the rebuild-fallback note at the right issue

The comment above `freed` said PR #193's xref-rebuild fallback would be the
natural home for recovering a spuriously-freed object. #193 shipped the
/Encrypt-in-XRefStm detection and the endstream hardening; it has no rebuild
fallback. Reconstruction is #184, still open.

Found while fixing the same defect class in the #196 corpus, where a comment
cited a Table 19 wording erratum for a question that erratum does not address.
A citation nobody can follow is worse than none — it spends the reader's trust
before they reach the part that is right.

* test(reader): make the freed-object deletion load-bearing

The reuse half of freed-object-reuse.pdf could not fail: revision 3 defines
5 1 obj, so it resolves whether or not revision 2's deletion was recorded.
Add object 7, freed in revision 2 and never redefined, where returning null
requires having honoured the free entry. Removing freed.UnionWith(localFreed)
now fails the test; before, it passed. qpdf discriminates here too, and the
revision-2 free list is linked per ISO 32000-2 §7.5.4.

Ask for the stale generation before the cache is warm. Resolving 5 1 first
cached object 5 at generation 1, so the 5 0 lookup exited on the cached value
without reaching the resolution path at all.

Five claims were wrong:

- The docs said an xref entry's generation must match the object header.
  Resolve never reads the header's generation when the xref is authoritative;
  rewriting 5 1 obj's header to 7 leaves the test green. The rule is that the
  reference's generation must match the entry's.
- The note on BrokenStartxref said the test failing once #184 lands would be a
  success signal. #197 is opt-in and defaults off, so it keeps passing — a
  failure would be the regression the note told a maintainer to wave through.
- qpdf returning null for object 5 was attributed to the deletion. A control
  with no free entry anywhere gives identical answers; it comes from the merged
  xref. Object 7 is where qpdf actually discriminates.
- The same-section hybrid case was described as unsettled "expert opinion
  included". Three participants in pdf-issues#237 lean the other way and none
  supports our reading. Say so, and that we differ deliberately (#206).
- One file still credited poppler with resolving the hidden object, retracted
  elsewhere in the previous pass.
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.

Reader: no third-party PDF fixture exists anywhere in the tree

1 participant