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

ValueError: Data must be padded to 16 byte boundary in CBC mode (Issue in PyPDF2 2.11.1) #338

Closed
peletiah opened this issue Nov 19, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@peletiah
Copy link

peletiah commented Nov 19, 2022

Just as a heads-up in case someone else encounters this issue.

While parsing several hundred files, I got this error-message for many of these files:
ValueError: Data must be padded to 16 byte boundary in CBC mode

This is an issue in the upstream PyPDF2-package at least in version 2.11.1.

There's a bug-report in the PyPDF2-repo and a 3-line quickfix has already been commited. I've modified PyPDF2/_encryption.py in my local site-package accordingly and no longer see the error. I assume the patch will soon be published in a package as well.

My PyPDF2-version is 2.11.1

Here's the full traceback for reference.

Traceback (most recent call last):
  File "/home/benke/workspace/solarkeymark_importer/parse_certificate.py", line 91, in <module>
    tables = camelot.read_pdf(f"{pdf_dir}{file}", pages='1-end', line_scale=110, shift_text=[''])
  File "/home/benke/workspace/solarkeymark_importer/lib/python3.10/site-packages/camelot/io.py", line 113, in read_pdf
    tables = p.parse(
  File "/home/benke/workspace/solarkeymark_importer/lib/python3.10/site-packages/camelot/handlers.py", line 169, in parse
    self._save_page(self.filepath, p, tempdir)
  File "/home/benke/workspace/solarkeymark_importer/lib/python3.10/site-packages/camelot/handlers.py", line 117, in _save_page
    outfile.write(f)
  File "/home/benke/workspace/solarkeymark_importer/lib/python3.10/site-packages/PyPDF2/_writer.py", line 841, in write
    self.write_stream(stream)
  File "/home/benke/workspace/solarkeymark_importer/lib/python3.10/site-packages/PyPDF2/_writer.py", line 814, in write_stream
    self._sweep_indirect_references(self._root)
  File "/home/benke/workspace/solarkeymark_importer/lib/python3.10/site-packages/PyPDF2/_writer.py", line 963, in _sweep_indirect_references
    data = self._resolve_indirect_object(data)
  File "/home/benke/workspace/solarkeymark_importer/lib/python3.10/site-packages/PyPDF2/_writer.py", line 1008, in _resolve_indirect_object
    real_obj = data.pdf.get_object(data)
  File "/home/benke/workspace/solarkeymark_importer/lib/python3.10/site-packages/PyPDF2/_reader.py", line 1231, in get_object
    retval = self._encryption.decrypt_object(
  File "/home/benke/workspace/solarkeymark_importer/lib/python3.10/site-packages/PyPDF2/_encryption.py", line 750, in decrypt_object
    return cf.decrypt_object(obj)
  File "/home/benke/workspace/solarkeymark_importer/lib/python3.10/site-packages/PyPDF2/_encryption.py", line 188, in decrypt_object
    obj[dictkey] = self.decrypt_object(value)
  File "/home/benke/workspace/solarkeymark_importer/lib/python3.10/site-packages/PyPDF2/_encryption.py", line 182, in decrypt_object
    data = self.strCrypt.decrypt(obj.original_bytes)
  File "/home/benke/workspace/solarkeymark_importer/lib/python3.10/site-packages/PyPDF2/_encryption.py", line 90, in decrypt
    d = aes.decrypt(data)
  File "/home/benke/workspace/solarkeymark_importer/lib/python3.10/site-packages/Crypto/Cipher/_mode_cbc.py", line 246, in decrypt
    raise ValueError("Data must be padded to %d byte boundary in CBC mode" % self.block_size)
ValueError: Data must be padded to 16 byte boundary in CBC mode
@peletiah peletiah added the bug Something isn't working label Nov 19, 2022
@peletiah peletiah reopened this Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant