COSStreamArray NullPointerException. firstStream is null if COSArray contains 
no items
--------------------------------------------------------------------------------------

                 Key: PDFBOX-898
                 URL: https://issues.apache.org/jira/browse/PDFBOX-898
             Project: PDFBox
          Issue Type: Bug
          Components: Parsing
    Affects Versions: 1.3.1
            Reporter: Martijn Brinkers


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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to