Skip to content

Reader A5: fixture corpus + fuzzing + CI round-trip oracles #99

Closed

Description

@Tim81

Part of the general PDF reader epic.

Status update, 2026-08-28. The fixture-corpus half is done. What remains is fuzzing and the
round-trip oracle, and the latter turns out to be blocked rather than merely unstarted.

Done — the corpus

Two committed corpora cover every axis this issue asked for:

Both were generated once with qpdf 12.3.2 and poppler 25.07.0, or hand-built where neither tool
can produce the construct, and committed rather than generated at test time — so the corpus is
byte-identical everywhere and there is no GateOnCi skip hole. Each has a README recording the exact
commands. (mutool, named in the original filing, was not used and is nowhere in the tree.)

Both corpora are SHA-256-pinned with MustContain/MustNotContain token scans, so a regeneration
that silently drops the construct a fixture exists for is caught rather than just re-baselined.

Remaining — lexer fuzzing

Nothing exists today: no harness, no fuzz job, no fuzzing dependency. Target
PdfLexer.NextToken + PdfObjectParser.ParseObject, seeded from the two corpora plus the
minimised inputs from every malformed-input bug already fixed
(MalformedInputTests.cs,
EncryptDictionaryDenialOfServiceTests.cs, PdfDictionaryIndexTests.cs) — those are the shapes the
parser is known to be fragile on.

A harness whose only passing condition is "no unhandled exception in N seconds" is satisfied on
iteration 1 and never regresses. Four things make it real:

  • An oracle, not just "doesn't crash". Assert that only InvalidDataException,
    UnsupportedPdfFeatureException and PdfPasswordException escape — an IndexOutOfRangeException,
    NullReferenceException, OutOfMemoryException or OverflowException is a finding. That
    vocabulary is already asserted by hand at ThirdPartyReaderBehaviorTests.cs:266-275. Add a
    per-input wall-clock and allocation ceiling; PdfDictionary is a linear scan, so building one is O(n²) — on the pre-authentication path #208 and fix(kernel): bound the cost of building a very large PdfDictionary #215 were both DoS fixes and the class is
    live.
  • Determinism. A fixed seed printed on failure. A fuzz failure that cannot be reproduced is a
    flaky test that gets deleted.
  • Crash triage → regression capture. On failure, write the minimised input as a CI artifact and
    require the fixing PR to commit it into Fixtures/Fuzz/ with a SHA pin and a token scan, exactly
    like the existing corpora. Each finding then becomes a permanent, fast, deterministic unit test and
    the seed corpus grows. Make capture the required output of a finding — otherwise "found nothing"
    and "findings were fixed without capture" are indistinguishable six months later.
  • Budget shape. Short and always-on for PRs; longer nightly with a persisted corpus. A fuzzer
    whose corpus resets each run explores the same first inputs forever.

On substrate: CsCheck is already a dependency (Apache-2.0, the repo's own licence), runs in-process
inside the normal dotnet test loop on Windows, has PCG-based automatic shrinking and CsCheck_Seed
replay, and iter:/time: budget control. SharpFuzz is AFL-based — "AFL works on Linux and
macOS"
, Windows needs WSL or libFuzzer — so it would be CI-only for this maintainer, reproducing the
exact complaint #198 exists to fix. Prefer CsCheck unless a spike shows otherwise.

Remaining — the CI round-trip oracle, blocked on #186

qpdf --check on re-serialized output presupposes a serializer for parsed documents, and the reader
has none. The only write path is PdfDocumentReader.AppendRevision
(src/VellumPdf.Reader/PdfDocumentReader.cs:951, internal), which copies the base file verbatim
and appends — so checking its output proves nothing about serialization. That serializer is #186.

Also worth folding in here: consolidate the per-file synthetic PDF builders. There are dozens of
private static byte[] Build… helpers spread across the test files with no shared type, and #184 and
#186 both add more.

Relates to

Activity

  1. added this to the milestone on Jun 16, 2026
  2. added
    area/ci
    type/chore
    area/reader
    on Jun 16, 2026
  3. modified the milestones: , v2.1 — PDF reader (structural) on Jun 16, 2026
  4. Tim81 commented on Aug 18, 2026

    @Tim81
    OwnerAuthor

    Validated the encrypted-fixture recipe against qpdf before anyone builds on it. Three findings, one of
    which would have produced silently empty fixtures.

    1. --allow-weak-crypto is required for RC4, and its absence fails silently-ish

    qpdf refuses RC4 by default:

    qpdf: refusing to write a file with RC4, a weak cryptographic algorithm

    It still creates the output file, at 0 bytes. ls shows it present. Anything that checked "the fixture
    exists" rather than "the fixture contains the feature" would sail straight past this — the exact trap
    CLAUDE.md describes. --allow-insecure does not help; that flag is about empty owner passwords on
    256-bit. The flag needed is --allow-weak-crypto, documented as "necessary to create 40-bit files or
    128-bit files that use RC4 encryption".

    2. Validated matrix

    Base is tests/VellumPdf.Kernel.Tests/GoldenTests.StandardFont_rawBytes.verified.pdf, first normalized
    through qpdf base.pdf so that encryption is the only delta against the plaintext baseline.
    Passwords: user u, owner o.

    Fixture qpdf arguments (after --encrypt u o) R Cipher
    enc-rc4-40 40 -- with --allow-weak-crypto 2 RC4-40
    enc-rc4-128 128 --use-aes=n -- with --allow-weak-crypto 3 RC4-128
    enc-rc4-128-v4 128 --force-V4 --use-aes=n -- with --allow-weak-crypto 4 RC4 via /CF /V2
    enc-aes-128 128 --use-aes=y -- 4 AESv2
    enc-aes-256-r5 256 --force-R5 -- 5 AESv3
    enc-aes-256-r6 256 -- 6 AESv3
    enc-256-cleartextmd 256 --cleartext-metadata -- 6 AESv3, metadata in clear

    That covers the whole #97 support matrix. Each fixture's R and cipher are confirmed by
    qpdf --password=u --show-encryption, which is the assertion to run before trusting any decrypt result.

    3. The KAT can be much stronger than "streams match"

    qpdf --password=u --decrypt on every one of the seven fixtures produces output byte-identical to the
    plaintext baseline except for 27 bytes, all in the second /ID array element (qpdf regenerates it;
    the first element is preserved). Verified across all seven.

    So the decrypt KAT can assert two things, not one:

    1. Decoded stream data byte-exact against the baseline — fully stable.
    2. Whole-file bytes byte-exact against the baseline once the second /ID element is normalized.

    The second is a far tighter net than comparing streams alone, and it is version-skew-immune because it
    compares our decrypted output to a checked-in plaintext baseline rather than to anything qpdf emits at
    test time.

    --cleartext-metadata is externally observable too: xpacket appears in the raw bytes of
    enc-256-cleartextmd.pdf and does not appear in enc-aes-256-r6.pdf. That is the same assertion shape
    #182 needs on the write side.

    Consequence for this issue

    Generate the corpus once and check the fixtures in, rather than generating at test time. CI qpdf is
    11.9.0 and local is 12.3.2; checked-in fixtures are byte-identical everywhere and take qpdf out of the
    test-execution path entirely, so there is no GateOnCi skip hole on the core corpus. Record the exact
    commands above in a README beside the fixtures.

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/ciarea/readertype/chore

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions