Repository navigation
test: hand-written minimal PDF corpus (#6) - #29
Merged
Merged
Conversation
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>
There was a problem hiding this comment.
🟡 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.
|
|
||
| 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))) |
8 tasks
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.

Closes #6
Adds
tests/Corpus/: 30 minimal hand-written PDFs, one feature per file, the stdlib-onlygenerate.pythat 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,Ifrom rectangles), so there is no third-party font or license in the repo.Files and verification (qpdf 12.4.2, poppler, fontconfig)
qpdf --checkempty-page.pdfpdf20-header.pdftext-standard14.pdfHello, Broadsidetext-truetype-embedded.pdfHI; pdffonts: TrueType WinAnsi emb=yes; fc-scan parses the font; pdftoppm renders both glyphsxref-stream.pdf--qdf --object-streams=disableeyeballedobject-stream.pdf--qdf --object-streams=disableshows objects 1-3 inflatedincremental-update.pdfhybrid-xref.pdfTitle: hybrid(reached only via/XRefStm)flate-stream.pdfFlateDecodelzw-stream.pdfLZWDecodeascii85-stream.pdfASCII85Decodeasciihex-stream.pdfASCIIHexDecoderunlength-stream.pdfRunLengthDecodefilter-chain.pdfASCII85 then Flatepng-predictor.pdfencrypted-rc4-40.pdfR = 2--password=owner --checkclean; pdftotext:RC4 40-bit (R2)encrypted-rc4-128.pdfR = 3RC4 128-bit (R3)encrypted-aes-128.pdfR = 4, AESv2AES-128 (R4)encrypted-aes-256.pdfR = 6, AESv3AES-256 (R6)broken-xref-offsets.pdfexpected n n obj, reconstructsmissing-endobj.pdfexpected endobjwrong-stream-length.pdfrecovered stream length: 47no-xref.pdfcan't find startxref,unable to find trailer dictionary, reconstructsstartxref-wrong.pdfxref not found, reconstructsinline-image.pdfpage-tree-inherited.pdfPage 1,Page 2via inherited resourcesannotations-link.pdf--jsonshows the/Linkdictionaryoutline.pdf--json --json-key=outlineslists both itemsname-tree-dests.pdfmetadata-xmp.pdfTitle: BroadsideThe exact qpdf and poppler messages for the broken files, and the
Diagnostica 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 matchestests/Corpus/on case-insensitive checkouts (macOS, Windows) because ignore matching honourscore.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