Use the repo’s files.json plus its PDF tree (default relative path in pdf/sample_files_test.go as sampleFilesRoot) as the single source of truth for smoke-testing pdf.OpenFile / NumPages / first-page geometry.
- Put the manifest and PDFs where the test constant points (root
.gitignoremay ignorereferences/; prepare locally or in CI). - From the module root:
go test ./pdf/... -run TestSampleFilesManifestAgainstReader -count=1- If
files.jsonis missing, the test Skips (not a failure).
For each files.json entry:
| Condition | Expectation |
|---|---|
encrypted: true |
OpenFile returns pdf.ErrEncrypted |
encrypted: false and not in skip map |
OpenFile succeeds; NumPages() equals pages; Page(0).MediaBox() exists |
| Missing file | Skip |
path |
Note |
|---|---|
017-unreadable-meta-data/unreadablemetadata.pdf |
Hybrid linearization + bad /Prev (into a NUL region). The reader stops invalid xref chains to avoid failing the whole file, but cannot rebuild the full object table from the first xref segment alone; many implementations still fail at xref repair or /Pages flattening. The test Skips this entry with a documented reason. |
If xref rebuild / more robust incremental parsing is added later, remove this Skip first, then satisfy the assertions above.
- Issue: manifest
startxrefpoints to an xref near the file head; that trailer’s/Prevpoints into an all-0x00region; continuing yields a bogus xref stream offset and errors. - Fix: in
reader_xref.go,xrefSegmentLooksValid: if the offset region starts with NUL, treat the segment as invalid and end the xref chain (common handling for broken incremental pointers), soErrXRefdoes not block other readable files.
- Stronger checks: for
encrypted: falsesamples with rich annotations, optionally assertAnnotDictscounts vs manifestannotations(must match manifest counting rules). - CI: workflow step cloning the corpus next to
sampleFilesRoot. - Cross-check: optional second process using another toolkit to compare page counts (higher cost; secondary gate only).