[
https://issues.apache.org/jira/browse/PDFBOX-2173?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
John Hewson closed PDFBOX-2173.
-------------------------------
Resolution: Fixed
Fix Version/s: 2.0.0
> Nullpointer when validating empty file
> --------------------------------------
>
> Key: PDFBOX-2173
> URL: https://issues.apache.org/jira/browse/PDFBOX-2173
> Project: PDFBox
> Issue Type: Bug
> Components: Preflight
> Affects Versions: 1.8.6
> Reporter: Per-Olof Widström
> Priority: Minor
> Fix For: 2.0.0
>
>
> 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 1.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.3.4#6332)