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

IndexError: list index out of range after decrypting encrypted file #327

Closed
denis-osipov opened this issue Feb 16, 2017 · 5 comments
Closed
Labels
is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF

Comments

@denis-osipov
Copy link
Contributor

After attempt to get page from encrypted file raise error 'PyPDF2.utils.PdfReadError: file has not been decrypted'.
It's ok. But after decrypting the PdfFileReader object calling pdfReader.getPage(0) raise error 'IndexError: list index out of range', although pdfReader.getNumPages() return 19.
If decript file before first call getPage() 'IndexError: list index out of range' doesn't raise.

>>> pdfFileObj = open('encrypted.pdf', 'rb')
>>> pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
>>> pdfReader.getPage(0)
Traceback (most recent call last):
 ...
  File "C:\Python36\lib\site-packages\PyPDF2\pdf.py", line 1617, in getObject
    raise utils.PdfReadError("file has not been decrypted")
PyPDF2.utils.PdfReadError: file has not been decryptedd
>>> pdfReader.decrypt('rosebud')
1
>>> pageObj = pdfReader.getPage(0)
Traceback (most recent call last):
...
  File "C:\Python36\lib\site-packages\PyPDF2\pdf.py", line 1177, in getPage
    return self.flattenedPages[pageNumber]
IndexError: list index out of range
>>> pdfReader.getNumPages()
19
@KeyC0de
Copy link

KeyC0de commented Jul 19, 2017

I experience the same exact error. Have you figured it out?

@denis-osipov
Copy link
Contributor Author

I think so. I make PR #359 that should solve the problem. At least it works for me.

@Topsolid1
Copy link

I'm having the same issues as you.
I manually fixed it since PR #359 isn't merged yet, and I can confirm that it works for me as well.
Thanks!

@shades6057
Copy link

denis-osipov, thanks, PR #359 fixed me as well. Had to also fix it manually.

Thanks!!

@MartinThoma MartinThoma added the is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF label Apr 7, 2022
MartinThoma added a commit that referenced this issue Apr 16, 2022
Credits to Denis Osipov:
#359 (comment)

Co-authored-by: Denis Osipov <osipov_d@list.ru>
@MartinThoma
Copy link
Member

@KeyC0de @Topsolid1 The fix was just merged and will be in the next release (some time this month). As the new maintainer, I hope to merge such fixes faster in future 🤞

MartinThoma added a commit that referenced this issue Apr 18, 2022
Deprecations (DEP):
-  Remove support for Python 2.6 and older (#776)

New Features (ENH):
-  Extract document permissions (#320)

Bug Fixes (BUG):
-  Clip by trimBox when merging pages, which would otherwise be ignored (#240)
-  Add overwriteWarnings parameter PdfFileMerger (#243)
-  IndexError for getPage() of decryped file (#359)
-  Handle cases where decodeParms is an ArrayObject (#405)
-  Updated PDF fields don't show up when page is written (#412)
-  Set Linked Form Value (#414)
-  Fix zlib -5 error for corrupt files (#603)
-  Fix reading more than last1K for EOF (#642)
-  Acciental import

Robustness (ROB):
-  Allow extra whitespace before "obj" in readObjectHeader (#567)

Documentation (DOC):
-  Link to pdftoc in Sample_Code (#628)
-  Working with annotations (#764)
-  Structure history

Developer Experience (DEV):
-  Add issue templates (#765)
-  Add tool to generate changelog

Maintenance (MAINT):
-  Use grouped constants instead of string literals (#745)
-  Add error module (#768)
-  Use decorators for @staticmethod (#775)
-  Split long functions (#777)

Testing (TST):
-  Run tests in CI once with -OO Flags (#770)
-  Filling out forms (#771)
-  Add tests for Writer (#772)
-  Error cases (#773)
-  Check Error messages (#769)
-  Regression test for issue #88
-  Regression test for issue #327

Code Style (STY):
-  Make variable naming more consistent in tests

All changes: 1.27.5...1.27.6
VictorCarlquist pushed a commit to VictorCarlquist/PyPDF2 that referenced this issue Apr 29, 2022
Deprecations (DEP):
-  Remove support for Python 2.6 and older (py-pdf#776)

New Features (ENH):
-  Extract document permissions (py-pdf#320)

Bug Fixes (BUG):
-  Clip by trimBox when merging pages, which would otherwise be ignored (py-pdf#240)
-  Add overwriteWarnings parameter PdfFileMerger (py-pdf#243)
-  IndexError for getPage() of decryped file (py-pdf#359)
-  Handle cases where decodeParms is an ArrayObject (py-pdf#405)
-  Updated PDF fields don't show up when page is written (py-pdf#412)
-  Set Linked Form Value (py-pdf#414)
-  Fix zlib -5 error for corrupt files (py-pdf#603)
-  Fix reading more than last1K for EOF (py-pdf#642)
-  Acciental import

Robustness (ROB):
-  Allow extra whitespace before "obj" in readObjectHeader (py-pdf#567)

Documentation (DOC):
-  Link to pdftoc in Sample_Code (py-pdf#628)
-  Working with annotations (py-pdf#764)
-  Structure history

Developer Experience (DEV):
-  Add issue templates (py-pdf#765)
-  Add tool to generate changelog

Maintenance (MAINT):
-  Use grouped constants instead of string literals (py-pdf#745)
-  Add error module (py-pdf#768)
-  Use decorators for @staticmethod (py-pdf#775)
-  Split long functions (py-pdf#777)

Testing (TST):
-  Run tests in CI once with -OO Flags (py-pdf#770)
-  Filling out forms (py-pdf#771)
-  Add tests for Writer (py-pdf#772)
-  Error cases (py-pdf#773)
-  Check Error messages (py-pdf#769)
-  Regression test for issue py-pdf#88
-  Regression test for issue py-pdf#327

Code Style (STY):
-  Make variable naming more consistent in tests

All changes: py-pdf/pypdf@1.27.5...1.27.6
MartinThoma pushed a commit that referenced this issue Jun 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF
Projects
None yet
Development

No branches or pull requests

5 participants