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

PDFBox StackOverflowError on malformed files when merging

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.4
    • Fix Version/s: 2.0.5, 3.0.0 PDFBox
    • Component/s: Utilities, Writing
    • Labels:
      None

      Description

      I supply 2 PDF files (certificate-of-analysis.pdf and questionario-sulle.pdf) which cause an exception if i try to merge them using PDFMergerUtility.

      I've implemented code examples which run to the exceptions:
      https://bitbucket.org/radistao/pdfbox-merge-bug/
      or just take the same sources from the attached radistao-pdfbox-merge-bug.zip

      Those 2 files are included into the repository (test/resources/).

      Error stack trace for certificate-of-analysis.pdf:

      • using addSource():

        java.lang.StackOverflowError
        at java.util.HashMap.hash(HashMap.java:338)
        at java.util.HashMap.containsKey(HashMap.java:595)
        at java.util.HashSet.contains(HashSet.java:203)
        at org.apache.pdfbox.pdfwriter.COSWriter.addObjectToWrite(COSWriter.java:472)
        at org.apache.pdfbox.pdfwriter.COSWriter.visitFromArray(COSWriter.java:927)
        at org.apache.pdfbox.cos.COSArray.accept(COSArray.java:515)
        at org.apache.pdfbox.pdfwriter.COSWriter.visitFromDictionary(COSWriter.java:1061)
        at org.apache.pdfbox.pdfwriter.COSWriter.visitFromDictionary(COSWriter.java:1020)
        at org.apache.pdfbox.pdfwriter.COSWriter.visitFromDictionary(COSWriter.java:1020)

      • using appendDocument()

        org.apache.pdfbox.cos.COSDocument finalize
        WARNING: Warning: You did not close a PDF Document
        org.apache.pdfbox.cos.COSDocument finalize
        WARNING: Warning: You did not close a PDF Document
        org.apache.pdfbox.cos.COSDocument finalize
        WARNING: Warning: You did not close a PDF Document
        org.apache.pdfbox.cos.COSDocument finalize
        WARNING: Warning: You did not close a PDF Document
        org.apache.pdfbox.cos.COSDocument finalize
        WARNING: Warning: You did not close a PDF Document

        java.lang.StackOverflowError
        at org.apache.pdfbox.pdfwriter.COSWriter.getObjectKey(COSWriter.java:892)
        at org.apache.pdfbox.pdfwriter.COSWriter.writeReference(COSWriter.java:1175)
        at org.apache.pdfbox.pdfwriter.COSWriter.visitFromArray(COSWriter.java:928)
        at org.apache.pdfbox.cos.COSArray.accept(COSArray.java:515)
        at org.apache.pdfbox.pdfwriter.COSWriter.visitFromDictionary(COSWriter.java:1061)
        at org.apache.pdfbox.pdfwriter.COSWriter.visitFromDictionary(COSWriter.java:1020)
        at org.apache.pdfbox.pdfwriter.COSWriter.visitFromDictionary(COSWriter.java:1020)
        at org.apache.pdfbox.pdfwriter.COSWriter.visitFromDictionary(COSWriter.java:1020)
        at org.apache.pdfbox.pdfwriter.COSWriter.visitFromDictionary(COSWriter.java:1020)

      Note: in version 1.8.13 (see https://bitbucket.org/radistao/pdfbox-merge-bug/branch/test/v1.8.13) file questionario-sulle.pdf merged fine (see attached merge result v1.8.13-PdfMergerAddSourceTest-questionario-sulle.pdf), but with just warnings:

      org.apache.pdfbox.pdfparser.PDFParser parseObject
      WARNING: expected='%%EOF' actual=''
      org.apache.pdfbox.pdfparser.XrefTrailerResolver setStartxref
      WARNING: Did not found XRef object at specified startxref position 0

        Attachments

        1. questionario-sulle+SDE.pdf
          776 kB
          Andrii Radistao
        2. v1.8.13-PdfMergerAddSourceTest-questionario-sulle.pdf
          619 kB
          Andrii Radistao
        3. radistao-pdfbox-merge-bug.zip
          586 kB
          Andrii Radistao
        4. questionario-sulle.pdf
          374 kB
          Andrii Radistao
        5. certificate-of-analysis.pdf
          19 kB
          Andrii Radistao

          Activity

            People

            • Assignee:
              tilman Tilman Hausherr
              Reporter:
              radistao Andrii Radistao
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: