[
https://issues.apache.org/jira/browse/PDFBOX-6364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18154656#comment-18154656
]
Simon Steiner commented on PDFBOX-6364:
---------------------------------------
The report lists three problems. On this branch (2.0), PDFBOX-6340 (commit
97378a7639) already fixed two of them:
- Rebuilding rectangles per glyph: fixed. fillBeadRectangles()
(PDFTextStripper.java:386) builds each rectangle once per page and caches it
in beadRectangles.
- NPE for a bead with no /R: fixed. A bead with no /R is stored as null, and
processTextPosition checks for null (PDFTextStripper.java:957).
Still open: nothing limits how many beads a page has. PDPage.getThreadBeads()
loads every /B entry. Each glyph is then tested against every cached rectangle
(glyphs × beads). processPage also creates 2·beads+1 article lists, and
writePage walks through all of them. A small compressed PDF that repeats one
bead reference millions of times therefore costs a lot of CPU and memory.
A related crash in the same area: PDThreadBead.getRectangle() casts /R to
COSArray without checking. If /R is not an array (e.g. /R /Foo), it throws
ClassCastException and extraction of the whole document stops.
> Text extraction checks every article bead for every glyph, so a small PDF can
> keep it busy for hours
> -----------------------------------------------------------------------------------------------------
>
> Key: PDFBOX-6364
> URL: https://issues.apache.org/jira/browse/PDFBOX-6364
> Project: PDFBox
> Issue Type: Bug
> Reporter: Simon Steiner
> Priority: Major
>
> With the default shouldSeparateByBeads=true, PDFTextStripper.processPage
> loads every entry of the page's /B (article bead) array with no limit. Then,
> for every glyph, processTextPosition loops over all of those beads,
> rebuilding each bead's PDRectangle from its /R entry and testing whether it
> contains the glyph. The work per page is glyphs × beads, and the document
> sets both numbers. A compressed PDF can repeat one bead reference very many
> times and show very many glyphs. Separately, a bead with no /R makes
> getRectangle() return null, and the unchecked rect.contains() throws
> NullPointerException, which aborts extraction of the whole document.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]