diff options
| author | nie <nie@odoo.com> | 2020-11-27 15:56:24 +0000 |
|---|---|---|
| committer | nie <nie@odoo.com> | 2021-01-11 09:07:04 +0000 |
| commit | 851fe64f7789bb398383c22e3ebbaebb051791f6 (patch) | |
| tree | 77733d30996f1d3076a2023f253f12058100d91c /odoo/tools | |
| parent | e6ccdb397792db62c3b08d96435b3c1667c1aa9d (diff) | |
[FIX] tools: try decrypting PDF with empty password
Steps:
- Install accounting
- On the dashboard, try to upload an "encrypted" PDF like this one https://launchpadlibrarian.net/24827090/DS-0157.pdf
Bug:
Traceback:
PyPDF2.utils.PdfReadError: file has not been decrypted
Explanation:
In 13.0, these errors were caught in a catch all `except` as shown here: https://github.com/odoo/odoo/blob/4e089041252c25cc197a30f9e285d82f7162d809/addons/account_facturx/models/account_move.py#L303-L328
From this SO comment: https://stackoverflow.com/questions/52047944/pdfbox-extracting-blanks-from-pdf-encrypted-with-no-password#comment91054285_52047944
> A PDF can be encrypted with two passwords: a user password and an owner password. When a PDF is encrypted with a user password, you can't open the document in a PDF viewer without entering that password. When a PDF is encrypted with an owner password only, everyone can open a PDF without that password, but some restrictions may be in place.
From time to time, we get a PDF encrypted with an owner password. The
content is still readable, but PyPDF2 fails because it thinks the PDF is
encrypted. With this fix, we try to unwrap the PDF by providing an empty
user password. This way, PyPDF2 thinks the content is now decrypted.
However, PyPDF2 only supports decrypting versions 1 and 2 of the
encryption implementation. If the version is different, we skip reading
the attachments and carry on to allow the user to upload the document.
opw:2375993
closes odoo/odoo#62557
Signed-off-by: backspac <backspac@users.noreply.github.com>
Diffstat (limited to 'odoo/tools')
| -rw-r--r-- | odoo/tools/pdf.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/odoo/tools/pdf.py b/odoo/tools/pdf.py index 66608c4b1ff..6929e2684ab 100644 --- a/odoo/tools/pdf.py +++ b/odoo/tools/pdf.py @@ -77,7 +77,14 @@ PdfFileReader.__init__ = lambda self, stream, strict=True, warndest=None, overwr class OdooPdfFileReader(PdfFileReader): # OVERRIDE of PdfFileReader to add the management of multiple embedded files. + ''' Returns the files inside the PDF. + :raises NotImplementedError: if document is encrypted and uses an unsupported encryption method. + ''' def getAttachments(self): + if self.isEncrypted: + # If the PDF is owner-encrypted, try to unwrap it by giving it an empty user password. + self.decrypt('') + if not self.trailer["/Root"].get("/Names", {}).get("/EmbeddedFiles", {}).get("/Names"): return [] for i in range(0, len(self.trailer["/Root"]["/Names"]["/EmbeddedFiles"]["/Names"]), 2): |
