Skip to content

test: hand-written minimal PDF corpus (#6) - #29

Merged
michaelstonis merged 1 commit into
mainfrom
6-minimal-corpus
Oct 9, 2026
Merged

michaelstonis merged 1 commit into
mainfrom
6-minimal-corpus

Conversation

@michaelstonis

Copy link
Copy Markdown
Owner

Closes #6

Adds tests/Corpus/: 30 minimal hand-written PDFs, one feature per file, the stdlib-only generate.py that emits them byte-deterministically (python3 -I tests/Corpus/generate.py), and a README with the feature, ISO 32000-2 clauses, verification commands and expected lenient-mode behaviour for every file.

The script computes xref offsets and stream lengths itself and implements the codecs and ciphers the corpus needs: LZW (early change 1), ASCII85, ASCIIHex, RunLength, PNG Up predictor, RC4, AES-128/256 (FIPS-197 known-answer self-test), and the standard security handler algorithms 1, 1.A, 2, 2.B, 3, 4, 5, 8, 9, 10 from clause 7.6.4. No external tool is used to produce any file. The embedded TrueType font is synthesized by the script (.notdef, H, I from rectangles), so there is no third-party font or license in the repo.

Files and verification (qpdf 12.4.2, poppler, fontconfig)

File qpdf --check Other
empty-page.pdf clean pdfinfo: 1 Letter page
pdf20-header.pdf clean pdfinfo: PDF version 2.0
text-standard14.pdf clean pdftotext: Hello, Broadside
text-truetype-embedded.pdf clean pdftotext: HI; pdffonts: TrueType WinAnsi emb=yes; fc-scan parses the font; pdftoppm renders both glyphs
xref-stream.pdf clean --qdf --object-streams=disable eyeballed
object-stream.pdf clean --qdf --object-streams=disable shows objects 1-3 inflated
incremental-update.pdf clean pdfinfo: 595 x 842 (A4) from the update
hybrid-xref.pdf clean pdfinfo: Title: hybrid (reached only via /XRefStm)
flate-stream.pdf clean pdftotext: FlateDecode
lzw-stream.pdf clean pdftotext: LZWDecode
ascii85-stream.pdf clean pdftotext: ASCII85Decode
asciihex-stream.pdf clean pdftotext: ASCIIHexDecode
runlength-stream.pdf clean pdftotext: RunLengthDecode
filter-chain.pdf clean pdftotext: ASCII85 then Flate
png-predictor.pdf clean xref stream decoded through Flate + Predictor 12
encrypted-rc4-40.pdf clean, R = 2 --password=owner --check clean; pdftotext: RC4 40-bit (R2)
encrypted-rc4-128.pdf clean, R = 3 as above; pdftotext: RC4 128-bit (R3)
encrypted-aes-128.pdf clean, R = 4, AESv2 as above; pdftotext: AES-128 (R4)
encrypted-aes-256.pdf clean, R = 6, AESv3 as above; pdftotext: AES-256 (R6)
broken-xref-offsets.pdf warns: expected n n obj, reconstructs pdfinfo recovers
missing-endobj.pdf warns: expected endobj pdfinfo clean
wrong-stream-length.pdf warns: recovered stream length: 47 pdftotext recovers the text
no-xref.pdf warns: can't find startxref, unable to find trailer dictionary, reconstructs poppler fails (exit 1)
startxref-wrong.pdf warns: xref not found, reconstructs pdfinfo clean
inline-image.pdf clean pdftoppm renders the 2x2 checkerboard
page-tree-inherited.pdf clean pdfinfo: 2 Letter pages; pdftotext: Page 1, Page 2 via inherited resources
annotations-link.pdf clean --json shows the /Link dictionary
outline.pdf clean --json --json-key=outlines lists both items
name-tree-dests.pdf clean
metadata-xmp.pdf clean pdfinfo: Title: Broadside

The exact qpdf and poppler messages for the broken files, and the Diagnostic a lenient reader is expected to record for each, are in the README.

Note for the reviewer

The ignore rule on line 12 of the repository's ignore file (corpus/) also matches tests/Corpus/ on case-insensitive checkouts (macOS, Windows) because ignore matching honours core.ignorecase. The files in this PR were force-added; once tracked they are unaffected, but new corpus files added on macOS will be silently ignored until the pattern is anchored to the root (/corpus/). That change is outside this PR's scope (tests/Corpus/ only), so it is left for a follow-up.

🤖 Generated with Claude Code

Adds tests/Corpus/ with 30 minimal PDFs, one feature per file, and the
stdlib-only generate.py that emits them deterministically (computed xref
offsets and stream lengths; LZW, ASCII85, ASCIIHex, RunLength and PNG
predictor encoders; RC4 and AES implemented in the script; standard
security handler R2, R3, R4 and R6 per ISO 32000-2 clause 7.6.4). The
README lists each file with its clauses, how it was verified with qpdf
and poppler, and what a lenient reader is expected to do with the five
deliberately broken files.

Closes #6

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 9, 2026 16:20
@michaelstonis
michaelstonis merged commit b0d0376 into main Oct 9, 2026
1 check passed
@michaelstonis
michaelstonis deleted the 6-minimal-corpus branch October 9, 2026 16:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two nominally well-formed fixtures omit the required binary header comment.

1 open finding
What changed in this PR

Adds a deterministic, hand-authored PDF corpus covering core structures, filters, encryption, rendering features, and malformed-input recovery.

Changes:

  • Adds 30 minimal PDF fixtures.
  • Adds a standard-library-only deterministic generator.
  • Documents clauses, verification, and expected diagnostics.
File Description
tests/​Corpus/​README.md Documents corpus and verification.
tests/​Corpus/​generate.py Generates all fixtures deterministically.
tests/​Corpus/​empty-page.pdf Minimal blank document.
tests/​Corpus/​pdf20-header.pdf PDF 2.0 header fixture.
tests/​Corpus/​text-standard14.pdf Standard 14 text.
tests/​Corpus/​text-truetype-embedded.pdf Embedded TrueType text.
tests/​Corpus/​xref-stream.pdf Cross-reference stream.
tests/​Corpus/​object-stream.pdf Compressed objects.
tests/​Corpus/​incremental-update.pdf Incremental revision.
tests/​Corpus/​hybrid-xref.pdf Hybrid cross-reference data.
tests/​Corpus/​flate-stream.pdf Flate filter.
tests/​Corpus/​lzw-stream.pdf LZW filter.
tests/​Corpus/​ascii85-stream.pdf ASCII85 filter.
tests/​Corpus/​asciihex-stream.pdf ASCIIHex filter.
tests/​Corpus/​runlength-stream.pdf RunLength filter.
tests/​Corpus/​filter-chain.pdf Chained filters.
tests/​Corpus/​png-predictor.pdf PNG predictor.
tests/​Corpus/​encrypted-rc4-40.pdf 40-bit RC4 encryption.
tests/​Corpus/​encrypted-rc4-128.pdf 128-bit RC4 encryption.
tests/​Corpus/​encrypted-aes-128.pdf AES-128 encryption.
tests/​Corpus/​encrypted-aes-256.pdf AES-256 encryption.
tests/​Corpus/​broken-xref-offsets.pdf Invalid xref offsets.
tests/​Corpus/​missing-endobj.pdf Missing object terminator.
tests/​Corpus/​wrong-stream-length.pdf Incorrect stream length.
tests/​Corpus/​no-xref.pdf Missing xref and trailer.
tests/​Corpus/​startxref-wrong.pdf Invalid startxref offset.
tests/​Corpus/​inline-image.pdf Inline image fixture.
tests/​Corpus/​page-tree-inherited.pdf Inherited page properties.
tests/​Corpus/​annotations-link.pdf Link annotation.
tests/​Corpus/​outline.pdf Document outline.
tests/​Corpus/​name-tree-dests.pdf Named destinations.
tests/​Corpus/​metadata-xmp.pdf XMP metadata.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/Corpus/generate.py

def gen_runlength_stream() -> bytes:
content = text_content(b"RunLengthDecode") + b" " * 10 # a run so the filter has something to do
return text_file(stream(b"/Filter /RunLengthDecode", runlength_encode(content)))
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.

[Scaffold] Minimal corpus

2 participants