Per-Olof Widström created PDFBOX-2173:
-----------------------------------------

             Summary: Nullpointer when validating empty file
                 Key: PDFBOX-2173
                 URL: https://issues.apache.org/jira/browse/PDFBOX-2173
             Project: PDFBox
          Issue Type: Bug
          Components: Preflight
            Reporter: Per-Olof Widström



I am validating a PDF and I am getting a NullpointerException when the filesize 
is 0 bytes. I looked at the code and saw a small misstake, and therefore I am 
reporting this. I use version 2.8.6

{code:java|title=PreflightParser.java}
    protected void checkPdfHeader()
    {
            //[snip]
            String secondLine = reader.readLine();
            byte[] secondLineAsBytes = secondLine.getBytes(encoding.name());
            if (secondLine != null && secondLineAsBytes.length >= 5)
            //[snip]
    }
{code}

As you can see {{secondLineAsBytes}} is checked for null value, but only after 
being called once.

{code}
java.lang.NullPointerException
        at 
org.apache.pdfbox.preflight.parser.PreflightParser.checkPdfHeader(PreflightParser.java:297)
        at 
org.apache.pdfbox.preflight.parser.PreflightParser.parse(PreflightParser.java:195)
        at 
org.apache.pdfbox.preflight.parser.PreflightParser.parse(PreflightParser.java:180)
        at 
org.apache.pdfbox.preflight.parser.PreflightParser.parse(PreflightParser.java:168)
{code}

h4. Workaround
Before validating, check the filesize, if it is larger than 0. 

h4. How to reproduce
Try to validate with an empty file.






--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to