veraPDF / veraPDF-library

Industry supported, open source PDF/A validation library
http://verapdf.org/software
GNU General Public License v3.0
278 stars 47 forks source link

NullPointerException in SeekableCOSParser.getStream #1464

Open Lolf1010 opened 4 months ago

Lolf1010 commented 4 months ago

Hi, we sometimes get the following exception in our application. Sadly i can not provide you with a pdf-file to replicate the exception - they are our users pdf-files.

Our code we are using VeraGreenfieldFoundryProvider Version 1.26.1

InputStream stream = ...
VeraPDFFoundry foundry = Foundries.defaultInstance()
PDFAParser parser = foundry.createParser(stream)

Stacktrace

java.lang.NullPointerException: Cannot invoke "java.lang.Boolean.booleanValue()" because the return value of "org.verapdf.cos.COSObject.isIndirect()" is null
at org.verapdf.parser.SeekableCOSParser.getStream(SeekableCOSParser.java:108)
at org.verapdf.parser.SeekableCOSParser.getDictionary(SeekableCOSParser.java:82)
at org.verapdf.parser.COSParser.nextObject(COSParser.java:157)
at org.verapdf.parser.PDFParser.getObject(PDFParser.java:303)
at org.verapdf.io.Reader.getObject(Reader.java:118)
at org.verapdf.io.Reader.getObject(Reader.java:89)
at org.verapdf.cos.COSDocument.getObject(COSDocument.java:229)
at org.verapdf.cos.COSIndirect.getDirect(COSIndirect.java:430)
at org.verapdf.cos.COSIndirect.getType(COSIndirect.java:79)
at org.verapdf.cos.COSObject.getType(COSObject.java:99)
at org.verapdf.pd.PDCatalog.getMetadata(PDCatalog.java:72)
at org.verapdf.gf.model.GFModelParser.obtainFlavour(GFModelParser.java:165)
at org.verapdf.gf.model.GFModelParser.detectFlavour(GFModelParser.java:102
at org.verapdf.gf.model.GFModelParser.<init>(GFModelParser.java:79) ~[validation-model-jakarta-1.26.1.jar!/:?]
at org.verapdf.gf.model.GFModelParser.createModelWithFlavour(GFModelParser.java:125)
at org.verapdf.gf.model.GFModelParser.createModelWithFlavour(GFModelParser.java:113)
at org.verapdf.gf.model.GFModelParser.createModelWithFlavour(GFModelParser.java:108)
at org.verapdf.gf.foundry.VeraFoundry.createParser(VeraFoundry.java:75)
at org.verapdf.gf.foundry.VeraFoundry.createParser(VeraFoundry.java:65)

Is this a bug? In the method COSObject.isIndirect there is a return null which causes the exception in the if-statement where the method is called from. I guess a Boolean.TRUE.equals should fix it. Alternatively, if this a bug in the pdf-file, i would have expected that a ModelParsingException is thrown.

Thanks.

MaximPlusov commented 4 months ago

@Lolf1010 thanks for reporting this issue! It's fixed in the latest dev version 1.27.32.