You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2014/12/17 23:55:14 UTC

[jira] [Commented] (PDFBOX-2574) StackOverflowError in PDFMerger with file that has recursion

    [ https://issues.apache.org/jira/browse/PDFBOX-2574?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14250743#comment-14250743 ] 

Tilman Hausherr commented on PDFBOX-2574:
-----------------------------------------

quick fix for people building from source:
in visitFromDictionary(), delete the segment that has two "item.setDirect(true);", i.e. this:
{code}
                    // write all XObjects as direct objects, this will save some size
                    COSBase item = dict.getItem(COSName.XOBJECT);
                    if(item!=null)
                    {
                        item.setDirect(true);
                    }
                    item = dict.getItem(COSName.RESOURCES);
                    if(item!=null)
                    {
                        item.setDirect(true);
                    }
{code}

> StackOverflowError in PDFMerger with file that has recursion
> ------------------------------------------------------------
>
>                 Key: PDFBOX-2574
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2574
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 1.8.8, 2.0.0
>            Reporter: Tilman Hausherr
>         Attachments: PDFBOX-2574-recursion.pdf, PDFBOX-2574-recursion_unc.pdf
>
>
> Reported by Marc Davis on the users mailing list: The attached file brings an exception when merging it with itself or with another file:
> {code}
> Exception in thread "main" java.lang.StackOverflowError
> 	at java.util.LinkedHashMap$LinkedHashIterator.<init>(LinkedHashMap.java:366)
> 	at java.util.LinkedHashMap$LinkedHashIterator.<init>(LinkedHashMap.java:366)
> 	at java.util.LinkedHashMap$EntryIterator.<init>(LinkedHashMap.java:412)
> 	at java.util.LinkedHashMap$EntryIterator.<init>(LinkedHashMap.java:412)
> 	at java.util.LinkedHashMap.newEntryIterator(LinkedHashMap.java:419)
> 	at java.util.HashMap$EntrySet.iterator(HashMap.java:1082)
> 	at org.apache.pdfbox.pdfwriter.COSWriter.visitFromDictionary(COSWriter.java:1016)
> 	at org.apache.pdfbox.pdfwriter.COSWriter.visitFromDictionary(COSWriter.java:1043)
> {code}
> and whole series of the last line.
> The file has a reference to itself in the resources. The problem is in an object stream:
> 21 0 22 166 23 339 24 1378 25 1548 26 2585 27 2750 28 3782 29 3960 30 5004 <</Count 1/Font<</F0 23 0 R/F1 25 0 R/F2 27 0 R/F3 29 0 R>>/Kids[9 0 R]/MediaBox[0 0 612.0 792.0]/ProcSet 30 0 R/Resources 21 0 R/Type/Pages/XObject<</Img0 19 0 R>>>>....
> "21 0 22 166 23 339 24 1378 25 1548 26 2585 27 2750 28 3782 29 3960 30 5004" tells where the objects start, i.e. object 21 starts at offset 0 (after the table), object 22 at offset 166, etc. The problem here is that "/Resources 21 0 R" points to itself. This isn't the only problem with this file... that object is a resource, yet it does have /kids. 
> I've also attached an uncompressed version of the file, it has the same problem but it is easier to see. There the problem is at "14 0 obj".



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)