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

ArrayIndexOutOfBoundsException when opening PDF file with invalid indirect reference #718

Closed
liefke opened this issue Apr 25, 2022 · 3 comments · Fixed by #719
Closed

ArrayIndexOutOfBoundsException when opening PDF file with invalid indirect reference #718

liefke opened this issue Apr 25, 2022 · 3 comments · Fixed by #719
Labels
Milestone

Comments

@liefke
Copy link

liefke commented Apr 25, 2022

I have a (confidential) PDF file, which can be opened by Acrobat Reader, Chrome and Firefox, but throws the following exception when opened with OpenPDF:

java.lang.ArrayIndexOutOfBoundsException: -1
	at java.util.ArrayList.elementData(ArrayList.java:422)
	at java.util.ArrayList.get(ArrayList.java:435)
	at com.lowagie.text.pdf.PdfReader.removeUnusedNode(PdfReader.java:3240)
	at com.lowagie.text.pdf.PdfReader.removeUnusedObjects(PdfReader.java:3285)
	at com.lowagie.text.pdf.PdfReader.readPdf(PdfReader.java:629)
	at com.lowagie.text.pdf.PdfReader.<init>(PdfReader.java:280)
	at com.lowagie.text.pdf.PdfReader.<init>(PdfReader.java:293)

Apparently an indirect reference in the PDF references a -1 (which is not valid according to the standard, but is ignored by most readers). I debugged the PDF and there is indeed a "-1 0 R" in one of the dictionary arrays, so no error in the PRTokeniser.

iText has fixed that a while ago, see here:
https://stackoverflow.com/questions/16699709/itext-throws-java-lang-arrayindexoutofboundsexception-on-creation-of-pdfreader

To Reproduce
Unfortunately I can't provide the PDF file here.

Expected behavior
Either throw an InvalidPdfException or (IMHO better) silently drop the invalid and unused reference.

Version

  • OpenPDF 1.3.27
@liefke liefke added the bug label Apr 25, 2022
liefke added a commit to liefke/OpenPDF that referenced this issue Apr 25, 2022
This was referenced Apr 25, 2022
@netmackan
Copy link
Contributor

We have also starting to get reports of this and can see the same stacktrace showing up since about 1-2 weeks ago and according to the report it is for PDF:s with version 1.7 and only for those produced by:

  • Microsoft Excel 2021
  • Microsoft Excel for Microsoft 365
  • Microsoft Powerpoint for Microsoft 365

Unfortunately, I can also not share any documents.

@liefke
Copy link
Author

liefke commented Apr 28, 2022

My PDF was created with Microsoft PowerPoint 2019 three weeks ago (2022-04-07). But as it was the first time that such an error was reported and as we have enough other documents that were created by Microsoft PowerPoint 2019 before, one could guess that a Microsoft update is responsible for the broken PDFs (and one could hope, that Microsoft will fix that soon, too).

@andreasrosdal
Copy link
Contributor

andreasrosdal commented May 9, 2022

I get the same problem. I hope that the pull request for this bug can be accepted.

java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 7770
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
at java.base/java.util.Objects.checkIndex(Objects.java:372)
at java.base/java.util.ArrayList.get(ArrayList.java:458)
at com.lowagie.text.pdf.PdfReader.removeUnusedNode(PdfReader.java:3240)
at com.lowagie.text.pdf.PdfReader.removeUnusedObjects(PdfReader.java:3285)
at com.lowagie.text.pdf.PdfReader.readPdf(PdfReader.java:629)
at com.lowagie.text.pdf.PdfReader.(PdfReader.java:212)
at com.lowagie.text.pdf.PdfReader.(PdfReader.java:196)

@asturio asturio linked a pull request May 11, 2022 that will close this issue
2 tasks
asturio pushed a commit that referenced this issue May 11, 2022
@asturio asturio added this to the 1.3.28 milestone May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants