You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2014/11/06 22:41:34 UTC
[jira] [Reopened] (PDFBOX-2173) Nullpointer when validating empty
file
[ https://issues.apache.org/jira/browse/PDFBOX-2173?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Tilman Hausherr reopened PDFBOX-2173:
-------------------------------------
> 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, 2.0.0
> Reporter: Per-Olof Widström
> Priority: Minor
> Fix For: 1.8.8, 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)