This release absorbs the open bug-fix PRs from ledongthuc/pdf with their original authorship preserved, adds our own fixes found while reviewing them, and hardens malformed-page handling.
Fixes
- Truncated PDF no longer OOMs:
readArraylooped forever appendingio.EOFas an object, allocating without bound (measured ~7 GB before OOM kill on a real-world file). Absorbed ledongthuc/pdf#79 by @spencerkimball, with its regression test. - Stray
]no longer panics:readObjecttreats]like>>— a dictionary with a missing value (<< /A ] >>) degrades instead of panicking. Absorbed from ledongthuc/pdf#64 by @yama6a; regression test added here. /Contentsstream arrays: a PDF object split across two content streams hung text extraction forever. Absorbed ledongthuc/pdf#76 by @rztaylor (one lexer over anio.MultiReader), with its regression test. On top of it, the concatenated streams are now separated with whitespace: raw concatenation glued adjacent tokens together (20+5lexes as205), silently corrupting text coordinates or panickingPage.Content()withbad Td.- Missing content stream: a page whose
/Contentshas no stream data panicked out ofPage.Content()and text extraction; it now degrades to an empty page. Idea from ledongthuc/pdf#46 by @utsav82, reimplemented (the original compared against a freshly constructed error, which never matches). - No more stdout pollution:
readDictprintedDEBUG: ...lines to the caller's stdout on dictionaries with non-name keys.
ledongthuc/pdf#58 by @roeey777 independently reached the same conclusions on both the readArray loop and the stream concatenation — credit to it as well.
Verification
Every fix ships with a regression test verified red on the previous code. Full suite runs under -race. Output on a production bank-statement corpus is byte-for-byte identical to v0.1.0.
What's next
ledongthuc/pdf#78 (hardening against malformed and hostile inputs, +1170 lines, 101 test assertions) is under review for the next release.
Install
go get github.com/chappihappymeal/pdf@v0.2.0