Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid NPE in StandardDecryption#finish #445

Merged

Conversation

sa-sh
Copy link

@sa-sh sa-sh commented Oct 31, 2020

NullPointerException occurs at com.lowagie.text.pdf.StandardDecryption#finish(StandardDecryption.java:105)
in PDF enctypted with AES while decrypting object of empty stream (cipher is not initialized in this case)

sample pdf object that causes NPE if try to modify (using PDFStamper) encrypted PDF with such object

    41 0 obj
    <</Length 0/Type/Pattern/PatternType 1/PaintType 1/TilingType 2/BBox[0 0 10 10]/XStep 10/YStep 10/Resources 42 0 R>>stream

    endstream
    endobj

stacktrace of error

java.lang.NullPointerException
	at com.lowagie.text.pdf.StandardDecryption.finish(StandardDecryption.java:105)
	at com.lowagie.text.pdf.PdfEncryption.decryptByteArray(PdfEncryption.java:582)
	at com.lowagie.text.pdf.PdfReader.getStreamBytesRaw(PdfReader.java:2355)
	at com.lowagie.text.pdf.PdfReader.getStreamBytesRaw(PdfReader.java:2385)
	at com.lowagie.text.pdf.PRStream.toPdf(PRStream.java:222)
	at com.lowagie.text.pdf.PdfIndirectObject.writeTo(PdfIndirectObject.java:164)
	at com.lowagie.text.pdf.PdfWriter$PdfBody.add(PdfWriter.java:410)
	at com.lowagie.text.pdf.PdfWriter.addToBody(PdfWriter.java:841)
	at com.lowagie.text.pdf.PdfStamperImp.close(PdfStamperImp.java:320)
	at com.lowagie.text.pdf.PdfStamper.close(PdfStamper.java:246)

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@asturio asturio merged commit 07ecaaf into LibrePDF:master Oct 31, 2020
@asturio asturio linked an issue Oct 31, 2020 that may be closed by this pull request
@sa-sh sa-sh deleted the bugfix/npe-aes-decryption-on-empty-array branch March 23, 2024 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NullPointerException on decrypting an empty stream
2 participants