Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-5801

StackOverflowError with specific document

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 2.0.31, 3.0.2 PDFBox
    • None
    • None
    • Windows 10 Pro - 19045.3208
      openjdk version "13.0.2" 2020-01-14
      Memory: -Xmx4G -Xms100m

    Description

      When i try to merge the attached file with a cover the error happens:

      >>java.lang.StackOverflowError
      >>    at java.base/sun.nio.cs.UTF_8$Decoder.decodeLoop(UTF_8.java:414)
      UTF_8.java:414
      >>    at java.base/java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:578)
      CharsetDecoder.java:578
      >>    at java.base/java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:801)
      CharsetDecoder.java:801
      >>    at org.apache.pdfbox.pdfparser.BaseParser.decodeBuffer(BaseParser.java:885)
      BaseParser.java:885
      >>    at org.apache.pdfbox.pdfparser.BaseParser.parseCOSName(BaseParser.java:872)
      BaseParser.java:872
      >>    at org.apache.pdfbox.pdfparser.BaseParser.parseCOSDictionaryNameValuePair(BaseParser.java:368)
      BaseParser.java:368
      >>    at org.apache.pdfbox.pdfparser.BaseParser.parseCOSDictionary(BaseParser.java:289)
      BaseParser.java:289
      >>    at org.apache.pdfbox.pdfparser.BaseParser.parseDirObject(BaseParser.java:915)
      BaseParser.java:915
      >>    at org.apache.pdfbox.pdfparser.COSParser.parseFileObject(COSParser.java:737)
      COSParser.java:737
      >>    at org.apache.pdfbox.pdfparser.COSParser.parseObjectDynamically(COSParser.java:671)
      COSParser.java:671
      >>    at org.apache.pdfbox.pdfparser.COSParser.dereferenceCOSObject(COSParser.java:625)
      COSParser.java:625
      >>    at org.apache.pdfbox.cos.COSObject.getObject(COSObject.java:121)
      COSObject.java:121
      >>    at org.apache.pdfbox.multipdf.PDFCloneUtility.hasSelfReference(PDFCloneUtility.java:249)
      PDFCloneUtility.java:249
      >>    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneCOSDictionary(PDFCloneUtility.java:176)
      PDFCloneUtility.java:176
      >>    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneCOSBaseForNewDocument(PDFCloneUtility.java:122)
      PDFCloneUtility.java:122
      >>    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:100)
      PDFCloneUtility.java:100
      >>    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneCOSBaseForNewDocument(PDFCloneUtility.java:110)
      PDFCloneUtility.java:110
      >>    at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:100)
      PDFCloneUtility.java:100{}

      The code is the following, tried different configs but none helped:

      PDFMergerUtility merger = new PDFMergerUtility();
      merger.addSource( cover );
      merger.addSource( file );
      merger.setDestinationFileName( location );
      merger.mergeDocuments(  null ); 

      A similar error happens if i try to extract a page of the file and save it in a new file:

       >>java.lang.StackOverflowError
      >>    at java.base/java.util.HashMap.putVal(HashMap.java:631)
      HashMap.java:631
      >>    at java.base/java.util.HashMap.put(HashMap.java:612)
      HashMap.java:612
      >>    at org.apache.pdfbox.pdfwriter.compress.COSObjectPool.put(COSObjectPool.java:80)
      COSObjectPool.java:80
      >>    at org.apache.pdfbox.pdfwriter.compress.COSWriterCompressionPool.addObjectToPool(COSWriterCompressionPool.java:141)
      COSWriterCompressionPool.java:141
      >>    at org.apache.pdfbox.pdfwriter.compress.COSWriterCompressionPool.addStructure(COSWriterCompressionPool.java:179)
      COSWriterCompressionPool.java:179
      >>    at org.apache.pdfbox.pdfwriter.compress.COSWriterCompressionPool.addElements(COSWriterCompressionPool.java:219)
      COSWriterCompressionPool.java:219
      >>    at org.apache.pdfbox.pdfwriter.compress.COSWriterCompressionPool.addStructure(COSWriterCompressionPool.java:188)
      COSWriterCompressionPool.java:188
      >>    at org.apache.pdfbox.pdfwriter.compress.COSWriterCompressionPool.addElements(COSWriterCompressionPool.java:219)

      The code is the following:

      PDDocument pdf = Loader.loadPDF( file );
             
      int pageCount = pdf.getNumberOfPages();
                 
      for ( int i = 0; i < pageCount; i++) {               
         PDDocument singlePageDocument = new PDDocument();  
         PDPage page = pdf.getPage(i);   
         singlePageDocument.addPage(page); 
         singlePageDocument.save( location + (i + 1) + ".pdf");  
         singlePageDocument.close(); 
      }
                 
      pdf.close(); 

      I believe theres is something to do with the specific structure of the file, considering i was able to use way bigger files, both in pages and in size without problems. 
      Also tried to use the same file on itext and no problem was found.

      Attachments

        1. arquivo.pdf
          23.18 MB
          Rodrigo Schonardt

        Activity

          People

            Unassigned Unassigned
            rodrigoschonardt Rodrigo Schonardt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: