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

COSStreamArray NullPointerException. firstStream is null if COSArray contains no items

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.3.1
    • 1.4.0
    • Parsing
    • None

    Description

      COSStreamArray checks whether array contains any items. If array is empty firstStream is not set and therefore null.

      public COSStreamArray( COSArray array )
      {
      super( new COSDictionary(), null );
      streams = array;
      if( array.size() > 0 )

      { firstStream = (COSStream)array.getObject( 0 ); }

      }

      Most methods of COSStreamArray however use firstStream without any checks which can result in a NullPointerException.

      I have a PDF that when parsed, results in a NPE because COSStreamArray#getScratchFile is called while firstStream is null.

      One option would be to not create an instance of COSStreamArray when there are no items in the array.

      A patch is attached that checks whether the array is empty and only creates an instance of there are any items.

      The PDF was created with:

      LaTeX with hyperref package
      PDF-1.2

      Attachments

        1. PDFBOX-898.patch
          0.6 kB
          Martijn Brinkers

        Activity

          People

            adamnichols Adam Nichols
            martijn_brinkers Martijn Brinkers
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: