Skip to content

v0.2.0 — absorbed upstream bug-fix PRs

Latest

Choose a tag to compare

@chappihappymeal chappihappymeal released this 24 Aug 12:48
· 9 commits to master since this release

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: readArray looped forever appending io.EOF as 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: readObject treats ] like >> — a dictionary with a missing value (<< /A ] >>) degrades instead of panicking. Absorbed from ledongthuc/pdf#64 by @yama6a; regression test added here.
  • /Contents stream arrays: a PDF object split across two content streams hung text extraction forever. Absorbed ledongthuc/pdf#76 by @rztaylor (one lexer over an io.MultiReader), with its regression test. On top of it, the concatenated streams are now separated with whitespace: raw concatenation glued adjacent tokens together (20 + 5 lexes as 205), silently corrupting text coordinates or panicking Page.Content() with bad Td.
  • Missing content stream: a page whose /Contents has no stream data panicked out of Page.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: readDict printed DEBUG: ... 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