diff options
| author | Benjamin Frantzen (bfr) <bfr@odoo.com> | 2020-06-03 08:52:25 +0000 |
|---|---|---|
| committer | Benjamin Frantzen (bfr) <bfr@odoo.com> | 2020-06-03 14:08:37 +0000 |
| commit | b1d19c61b1e3318be7b940fda6abfb3591c90c7d (patch) | |
| tree | 50f33481a8dd0c9452a51918f22ed5e526d63cc6 /odoo/tools | |
| parent | 42a424db20eaf51f3afc11cefeb0c1f9afcfe66d (diff) | |
[FIX] tools.pdf: do not crash when PDF has no attachments
Depending on the PDF version and the presence of embedded files, the PDF
document catalog `trailer["/Root"]` may not have any Name Dictionary
`["/Names"]`, and the latter may not have any `EmbeddedFiles` entry.
In that case `getAttachments()` should return an empty list rather than
raising a `KeyError`.
closes odoo/odoo#52312
Ref: Section 7.7.2, 7.7.4 and 7.11.4 of [PDF 1.7 spec](https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf)
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
Diffstat (limited to 'odoo/tools')
| -rw-r--r-- | odoo/tools/pdf.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/odoo/tools/pdf.py b/odoo/tools/pdf.py index 9003ad64789..8e317fa2bde 100644 --- a/odoo/tools/pdf.py +++ b/odoo/tools/pdf.py @@ -59,7 +59,7 @@ class OdooPdfFileReader(PdfFileReader): # OVERRIDE of PdfFileReader to add the management of multiple embedded files. def getAttachments(self): - if "/Names" not in self.trailer["/Root"]: + 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): attachment = self.trailer["/Root"]["/Names"]["/EmbeddedFiles"]["/Names"][i+1].getObject() |
