summaryrefslogtreecommitdiff
path: root/odoo
diff options
context:
space:
mode:
authorwan <wan@odoo.com>2021-03-04 16:59:36 +0000
committerwan <wan@odoo.com>2021-03-08 08:31:58 +0000
commitf4cc0579a3e0ee9c117c7dd0f6090edc6e94384d (patch)
tree4437a1190ce96fc0a4985e18d62fd1377c70d56e /odoo
parent4a8cc2ef2b0c8508c94b00bcde6d6ab6dba8edf7 (diff)
[FIX] tools: support malformed more malformed pdf
We do not want to fail ever if loading the attachment fails. We still log a warning in every case though. Some malformed PDFs lead to seeking the wrong bytes while looking for some parts, raising a ValueError closes odoo/odoo#67283 Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
Diffstat (limited to 'odoo')
-rw-r--r--odoo/tools/pdf.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/odoo/tools/pdf.py b/odoo/tools/pdf.py
index 6929e2684ab..91ceadcb5f0 100644
--- a/odoo/tools/pdf.py
+++ b/odoo/tools/pdf.py
@@ -85,10 +85,16 @@ class OdooPdfFileReader(PdfFileReader):
# 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"):
+ try:
+ file_path = self.trailer["/Root"].get("/Names", {}).get("/EmbeddedFiles", {}).get("/Names")
+ except Exception:
+ # malformed pdf (i.e. invalid xref page)
return []
- for i in range(0, len(self.trailer["/Root"]["/Names"]["/EmbeddedFiles"]["/Names"]), 2):
- attachment = self.trailer["/Root"]["/Names"]["/EmbeddedFiles"]["/Names"][i+1].getObject()
+
+ if not file_path:
+ return []
+ for i in range(0, len(file_path), 2):
+ attachment = file_path[i+1].getObject()
yield (attachment["/F"], attachment["/EF"]["/F"].getObject().getData())